**** Merged from MCS ****
[mono-project.git] / mcs / tools / sample_cast_const.cs
blob04969312cde2ba2e18a9c930d12defdb4a8a2790
1 using System;
3 class X {
4 static void w (string s)
6 Console.WriteLine ("\t" + s);
9 static void Main ()
11 object [,] names =
12 { { "Byte", "byte" },
13 { "SByte", "sbyte" },
14 { "Short", "short" },
15 { "UShort", "ushort" },
16 { "Int", "int32" },
17 { "UInt", "uint32" },
18 { "Long", "int64" },
19 { "ULong", "uint64" },
20 { "Float", "float" },
21 { "Double", "double" },
22 { null, null }
25 for (int i = 0; names [i,0] != null; i++){
26 string big = names [i, 0] + "Constant";
27 string small = "TypeManager." + names [i, 1] + "_type";
28 string nat = ((string) names [i,0]).ToLower ();
30 w ("\t\tif (expr is " + big + "){");
31 w ("\t\t\t" + nat + " v = ((" + big + ") expr).Value;");
32 w ("");
34 for (int j = 0; names [j,0] != null; j++){
35 string b = names [j, 0] + "Constant";
36 string s = "TypeManager." + names [j, 1] + "_type";
37 string n = ((string) names [j,0]).ToLower ();
39 if (i == j)
40 continue;
42 w ("\t\t\tif (target_type == " + s + ")");
43 w ("\t\t\t\treturn new " + b + " ((" + n + ") v);");
45 w ("\t\t}");