sample_cast_const.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. class X {
  3. static void w (string s)
  4. {
  5. Console.WriteLine ("\t" + s);
  6. }
  7. static void Main ()
  8. {
  9. object [,] names =
  10. { { "Byte", "byte" },
  11. { "SByte", "sbyte" },
  12. { "Short", "short" },
  13. { "UShort", "ushort" },
  14. { "Int", "int32" },
  15. { "UInt", "uint32" },
  16. { "Long", "int64" },
  17. { "ULong", "uint64" },
  18. { "Float", "float" },
  19. { "Double", "double" },
  20. { null, null }
  21. };
  22. for (int i = 0; names [i,0] != null; i++){
  23. string big = names [i, 0] + "Constant";
  24. string small = "TypeManager." + names [i, 1] + "_type";
  25. string nat = ((string) names [i,0]).ToLower ();
  26. w ("\t\tif (expr is " + big + "){");
  27. w ("\t\t\t" + nat + " v = ((" + big + ") expr).Value;");
  28. w ("");
  29. for (int j = 0; names [j,0] != null; j++){
  30. string b = names [j, 0] + "Constant";
  31. string s = "TypeManager." + names [j, 1] + "_type";
  32. string n = ((string) names [j,0]).ToLower ();
  33. if (i == j)
  34. continue;
  35. w ("\t\t\tif (target_type == " + s + ")");
  36. w ("\t\t\t\treturn new " + b + " ((" + n + ") v);");
  37. }
  38. w ("\t\t}");
  39. }
  40. }
  41. }