1 // This example illustrates global variable access from C#. 2 3 using System; 4 using System.Reflection; 5 6 public class runme { 7 Main()8 public static void Main() { 9 10 // Try to set the values of some global variables 11 12 example.ivar = 42; 13 example.svar = -31000; 14 example.lvar = 65537; 15 example.uivar = 123456; 16 example.usvar = 61000; 17 example.ulvar = 654321; 18 example.scvar = -13; 19 example.ucvar = 251; 20 example.cvar = 'S'; 21 example.fvar = (float)3.14159; 22 example.dvar = 2.1828; 23 example.strvar = "Hello World"; 24 example.iptrvar= example.new_int(37); 25 example.ptptr = example.new_Point(37,42); 26 example.name = "Bill"; 27 28 // Now print out the values of the variables 29 30 Console.WriteLine( "Variables (values printed from C#)" ); 31 32 Console.WriteLine( "ivar =" + example.ivar ); 33 Console.WriteLine( "svar =" + example.svar ); 34 Console.WriteLine( "lvar =" + example.lvar ); 35 Console.WriteLine( "uivar =" + example.uivar ); 36 Console.WriteLine( "usvar =" + example.usvar ); 37 Console.WriteLine( "ulvar =" + example.ulvar ); 38 Console.WriteLine( "scvar =" + example.scvar ); 39 Console.WriteLine( "ucvar =" + example.ucvar ); 40 Console.WriteLine( "fvar =" + example.fvar ); 41 Console.WriteLine( "dvar =" + example.dvar ); 42 Console.WriteLine( "cvar =" + example.cvar ); 43 Console.WriteLine( "strvar =" + example.strvar ); 44 Console.WriteLine( "cstrvar =" + example.cstrvar ); 45 Console.WriteLine( "iptrvar =" + example.iptrvar ); 46 Console.WriteLine( "name =" + example.name ); 47 Console.WriteLine( "ptptr =" + example.ptptr + example.Point_print(example.ptptr) ); 48 Console.WriteLine( "pt =" + example.pt + example.Point_print(example.pt) ); 49 50 Console.WriteLine( "\nVariables (values printed from C)" ); 51 52 example.print_vars(); 53 54 Console.WriteLine( "\nNow I'm going to try and modify some read only variables" ); 55 Console.WriteLine( "\nChecking that the read only variables are readonly..." ); 56 57 example ex = new example(); 58 Type t = ex.GetType(); 59 60 Console.WriteLine( " 'path'" ); 61 PropertyInfo pi = t.GetProperty("path"); 62 if (pi.CanWrite) 63 Console.WriteLine("Oh dear this variable is not read only\n"); 64 else 65 Console.WriteLine("Good."); 66 67 Console.WriteLine( " 'status'" ); 68 pi = t.GetProperty("status"); 69 if (pi.CanWrite) 70 Console.WriteLine("Oh dear this variable is not read only"); 71 else 72 Console.WriteLine("Good."); 73 74 Console.WriteLine( "\nI'm going to try and update a structure variable.\n" ); 75 76 example.pt = example.ptptr; 77 78 Console.WriteLine( "The new value is" ); 79 example.pt_print(); 80 Console.WriteLine( "You should see the value" + example.Point_print(example.ptptr) ); 81 } 82 } 83