Advertisement
Guest User

extensions

a guest
Jul 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.34 KB | None | 0 0
  1. public static class StringExtensions
  2.     {
  3.         public static string GetRightName(this string s)
  4.         {
  5.             switch (s)
  6.             {
  7.                 case "object":
  8.                     return "@object";
  9.                 case "base":
  10.                     return "@base";
  11.                 case "params":
  12.                     return "@params";
  13.                 default:
  14.                     return s;
  15.             }
  16.         }
  17.  
  18.         public static string Uppercase(this string s) => char.ToUpper(s[0]) + s.Substring(1);
  19.  
  20.         public static string GetRightType(this string s)
  21.         {
  22.             switch (s)
  23.             {
  24.                 case "uint16":
  25.                     return "ushort";
  26.                 case "uint32":
  27.                     return "uint";
  28.                 case "int16":
  29.                     return "short";
  30.                 case "float32":
  31.                     return "float";
  32.                 case "float64":
  33.                     return "double";
  34.                 case "int8":
  35.                     return "sbyte";
  36.                 case "uint8":
  37.                     return "byte";
  38.                 case "int32":
  39.                     return "int";
  40.                 case "int64":
  41.                     return "long";
  42.                 default:
  43.                     return s;
  44.             }
  45.         }
  46.  
  47.         public static string GetRightCastWriteMethod(string writeMethod)
  48.         {
  49.             switch (writeMethod)
  50.             {
  51.                 case "writeVarInt":
  52.                     return "int";
  53.                 case "writeVarShort":
  54.                     return "short";
  55.                 default:
  56.                     return "short";
  57.             }
  58.         }
  59.  
  60.         public static string GetRigthCast(string type, string writeMethod)
  61.         {
  62.             switch (type)
  63.             {
  64.                 case "uint32":
  65.                     switch (writeMethod)
  66.                     {
  67.                         case "writeVarInt":
  68.                             return "(int)";
  69.                         case "readVarInt":
  70.                             return "(uint)";
  71.                         case "writeInt":
  72.                             return "(int)";
  73.                         case "readInt":
  74.                             return "(uint)";
  75.                         default:
  76.                             return "";
  77.                     }
  78.                 case "int8":
  79.                     switch (writeMethod)
  80.                     {
  81.                         case "writeByte":
  82.                             return "(byte)";
  83.                         case "readByte":
  84.                             return "(sbyte)";
  85.                         default:
  86.                             return "";
  87.                     }
  88.                 case "uint16":
  89.                     switch (writeMethod)
  90.                     {
  91.                         case "writeVarShort":
  92.                             return "(short)";
  93.                         case "readVarShort":
  94.                             return "(ushort)";
  95.                         case "readShort":
  96.                             return "(ushort)";
  97.                         case "writeShort":
  98.                             return "(short)";
  99.                         default:
  100.                             return "";
  101.                     }
  102.                 default:
  103.                     return "";
  104.             }
  105.         }
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement