2005-04-12 Dick Porter <dick@ximian.com>
[mono.git] / mcs / tools / misc / sample_cast_const.cs
1 using System;
2
3 class X {
4         static void w (string s)
5         {
6                 Console.WriteLine ("\t" + s);
7         }
8         
9         static void Main ()
10         {
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 }
23                         };
24
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 ();
29                         
30                         w ("\t\tif (expr is " + big + "){");
31                         w ("\t\t\t" + nat + " v = ((" + big + ") expr).Value;");
32                         w ("");
33
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 ();
38
39                                 if (i == j)
40                                         continue;
41                                 
42                                 w ("\t\t\tif (target_type == " + s + ")");
43                                 w ("\t\t\t\treturn new " + b + " ((" + n + ") v);");
44                         }
45                         w ("\t\t}");
46                 }
47         }
48 }
49