public static int Sum(int a, double b, int c, float d, __arglist) { ArgIterator args = new ArgIterator(__arglist); int S = a + (int)b + c + (int)d; while(args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(int).TypeHandle)) { int N = __refvalue(args.GetNextArg(), int); Console.WriteLine("int value is "+N); S = S + N; } else if (args.GetNextArgType().Equals(typeof(string).TypeHandle)) { string s = __refvalue(args.GetNextArg(), string); Console.WriteLine("string value is "+s); } else if (args.GetNextArgType().Equals(typeof(MyStruct).TypeHandle)) { MyStruct st = __refvalue(args.GetNextArg(), MyStruct); Console.WriteLine("MyStruct value is "+st.x+" "+st.y); S = S + 2*st.x + 3*st.y; } else return -1; } return S; }
// Helper method for "TestArgIteratorGetType". private void TestTypes(String testNum, Type[] types, __arglist) { ArgIterator iter = new ArgIterator(__arglist); int count = iter.GetRemainingCount(); AssertEquals("Length " + testNum, types.Length, count); while(count > 0) { Type type = Type.GetTypeFromHandle (iter.GetNextArgType()); AssertEquals("TypeCheck " + testNum, types[types.Length - count], type); AssertEquals("Remaining " + testNum, count, iter.GetRemainingCount()); iter.GetNextArg(); --count; } try { iter.GetNextArgType(); Fail("EndCheck " + testNum); } catch(InvalidOperationException) { // We expect this exception at the end of the list. } AssertEquals("Remaining " + testNum, 0, iter.GetRemainingCount()); }
public static int Sum(int a, double b, int c, float d, __arglist) { ArgIterator args = new ArgIterator(__arglist); int S = a + (int)b + c + (int)d; while (args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(int).TypeHandle)) { int N = __refvalue(args.GetNextArg(), int); Console.WriteLine("int value is " + N); S = S + N; } else if (args.GetNextArgType().Equals(typeof(string).TypeHandle)) { string s = __refvalue(args.GetNextArg(), string); Console.WriteLine("string value is " + s); } else if (args.GetNextArgType().Equals(typeof(MyStruct).TypeHandle)) { MyStruct st = __refvalue(args.GetNextArg(), MyStruct); Console.WriteLine("MyStruct value is " + st.x + " " + st.y); S = S + 2 * st.x + 3 * st.y; } else { return(-1); } } return(S); }
public static long EnumTest(__arglist) { ArgIterator args = new ArgIterator(__arglist); long S = 0; while (args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(Enum1).TypeHandle)) { Enum1 e = __refvalue(args.GetNextArg(), Enum1); Console.WriteLine("Got Enum1, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enum8).TypeHandle)) { Enum8 e = __refvalue(args.GetNextArg(), Enum8); Console.WriteLine("Got Enum8, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enum16).TypeHandle)) { Enum16 e = __refvalue(args.GetNextArg(), Enum16); Console.WriteLine("Got Enum16, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enuml).TypeHandle)) { Enuml e = __refvalue(args.GetNextArg(), Enuml); Console.WriteLine("Got Enuml, value = " + e + " = " + (long)e); S += (long)e; } } return(S); }
// Helper method for "TestArgIteratorGetType". private void TestTypes(String testNum, Type[] types, __arglist) { ArgIterator iter = new ArgIterator(__arglist); int count = iter.GetRemainingCount(); AssertEquals("Length " + testNum, types.Length, count); while (count > 0) { Type type = Type.GetTypeFromHandle (iter.GetNextArgType()); AssertEquals("TypeCheck " + testNum, types[types.Length - count], type); AssertEquals("Remaining " + testNum, count, iter.GetRemainingCount()); iter.GetNextArg(); --count; } try { iter.GetNextArgType(); Fail("EndCheck " + testNum); } catch (InvalidOperationException) { // We expect this exception at the end of the list. } AssertEquals("Remaining " + testNum, 0, iter.GetRemainingCount()); }
public static long EnumTest(__arglist) { ArgIterator args = new ArgIterator(__arglist); long S = 0; while (args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(Enum1).TypeHandle)) { Enum1 e = __refvalue(args.GetNextArg(), Enum1); Console.WriteLine("Got Enum1, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enum8).TypeHandle)) { Enum8 e = __refvalue(args.GetNextArg(), Enum8); Console.WriteLine("Got Enum8, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enum16).TypeHandle)) { Enum16 e = __refvalue(args.GetNextArg(), Enum16); Console.WriteLine("Got Enum16, value = " + e + " = " + (long)e); S += (long)e; } if (args.GetNextArgType().Equals(typeof(Enuml).TypeHandle)) { Enuml e = __refvalue(args.GetNextArg(), Enuml); Console.WriteLine("Got Enuml, value = " + e + " = " + (long)e); S += (long)e; } } return S; }
public void TestArgIteratorUninitialized() { AssertEquals("Remaining", 0, emptyIterator.GetRemainingCount()); try { emptyIterator.GetNextArg(); Fail("EndCheck"); } catch (InvalidOperationException) { // We expect this exception at the end of the list. } try { emptyIterator.GetNextArgType(); Fail("EndCheck 2"); } catch (InvalidOperationException) { // We expect this exception at the end of the list. } try { emptyIterator.GetNextArg(typeof(int).TypeHandle); Fail("EndCheck 3"); } catch (InvalidOperationException) { // We expect this exception at the end of the list. } }
private static void testArglist(__arglist) { const int newint = 10; const double newdouble = 0.1; ArgIterator iter = new ArgIterator(__arglist); int length = iter.GetRemainingCount(); for (int i = 0; i < length; i++) { Type type = Type.GetTypeFromHandle(iter.GetNextArgType()); if (type == typeof(int)) { int v = __refvalue(iter.GetNextArg(), int); Debug.WriteLine("Found int with value:{0}", v); v = newint; continue; } if (type == typeof(double)) { double v = __refvalue(iter.GetNextArg(), double); Debug.WriteLine("Found double with value:{0}", v); v = newdouble; continue; } Debug.WriteLine("Missing object:{0}", TypedReference.ToObject(iter.GetNextArg())); } }
public static void argit3(__arglist) { ArgIterator args = new ArgIterator(__arglist); try { int argCount = args.GetRemainingCount(); for (int i = 0; i < argCount; i++) { TypedReference trTypRef = args.GetNextArg(); } } catch (Exception ex) { throw new Exception("ExcErr007 ," + ex.ToString()); } for (int j = 0; j < 5; j++) { try { RuntimeTypeHandle rthRunTypHan = args.GetNextArgType(); throw new Exception("ExcErr006 , Last call should have thrown."); } catch (InvalidOperationException) {} } }
public Type[] argit7(__arglist) { Console.WriteLine(1); ArgIterator args = new ArgIterator(__arglist); int iCount = args.GetRemainingCount(); Type[] typArr = new Type[iCount]; for (int i = 0; i < iCount; i++) { Console.WriteLine(" -> " + typeof(System.TypedReference).TypeHandle.Value); Console.WriteLine(" => " + args.GetNextArgType()); } return(typArr); }
object getInnerHandle(__arglist) { RuntimeArgumentHandle handle = __arglist; ArgIterator args = new ArgIterator(handle); var mi = typeof(ArgIterator).GetMembers(); var meth = typeof(ArgIterator).GetMethod("GetNextArg", Type.EmptyTypes); var il = meth.GetMethodBody().GetILAsByteArray(); //ExecuteTyped(meth, __arglist(handle)); var t = args.GetNextArgType(); TypedReference tr = args.GetNextArg(); var targetType = TypedReference.GetTargetType(tr); var typedObject = TypedReference.ToObject(tr); return(typedObject); }
private static void VerifyTypes(Type[] types, __arglist) { ArgIterator args = new ArgIterator(__arglist); int argCount = args.GetRemainingCount(); Assert.Equal(types.Length, argCount); object[] objArgs = new Object[argCount]; for (int i = 0; i < argCount; i++) { RuntimeTypeHandle handle = args.GetNextArgType(); Type type = Type.GetTypeFromHandle(handle); Assert.Equal(types[i], type); args.GetNextArg(handle); } }
public void argit2( __arglist ) { ArgIterator args = new ArgIterator( __arglist ); try { int argCount = args.GetRemainingCount(); for (int i = 0; i < argCount; i++) { TypedReference trTypRef = args.GetNextArg(); } } catch(Exception ex) { throw new Exception( "ExcErr007 ," + ex.ToString() ); } for ( int j = 0; j < 5; j++ ) { try { RuntimeTypeHandle rthRunTypHan = args.GetNextArgType(); throw new Exception( "ExcErr006 , Last call should have thrown." ); } catch (InvalidOperationException){} } }
public Type[] argit7( __arglist ) { Console.WriteLine( 1 ); ArgIterator args = new ArgIterator( __arglist ); int iCount = args.GetRemainingCount(); Type[] typArr = new Type[iCount]; for ( int i = 0; i < iCount; i++ ) { Console.WriteLine( " -> " + typeof( System.TypedReference ).TypeHandle.Value ); Console.WriteLine( " => " + args.GetNextArgType() ); } return typArr; }
public MyStruct SumAndCount(int a, int b, __arglist) { Console.WriteLine("This type: " + this.GetType().ToString()); MyStruct t = new MyStruct(); ArgIterator args = new ArgIterator(__arglist); t.x += (a + b); t.y += args.GetRemainingCount(); while(args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(int).TypeHandle)) { int N = __refvalue(args.GetNextArg(), int); Console.WriteLine("int value is "+N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(byte).TypeHandle)) { byte N = __refvalue(args.GetNextArg(), byte); Console.WriteLine("byte value is "+N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(short).TypeHandle)) { short N = __refvalue(args.GetNextArg(), short); Console.WriteLine("short value is "+N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(long).TypeHandle)) { TypedReference tr = args.GetNextArg(); Interlocked.Increment(ref __refvalue(tr, long)); long N = __refvalue(tr, long); Console.WriteLine("long value is "+N); t.x = t.x + (int)(N % 57); } else if (args.GetNextArgType().Equals(typeof(float).TypeHandle)) { float N = __refvalue(args.GetNextArg(), float); Console.WriteLine("float value is "+N); t.x = t.x + (int)N; } else if (args.GetNextArgType().Equals(typeof(double).TypeHandle)) { double N = __refvalue(args.GetNextArg(), double); Console.WriteLine("double value is "+N); t.x = t.x + (int)N; } else if (args.GetNextArgType().Equals(typeof(Struct1).TypeHandle)) { Struct1 N = __refvalue(args.GetNextArg(), Struct1); Console.WriteLine("Struct1 value is "+N.x); t.x = t.x + N.x; } else throw new Exception(); } return t; }
public static void argit2(__arglist) { ArgIterator args = new ArgIterator(__arglist); Object o = args.GetNextArgType(); }
public static void argit2( __arglist ) { ArgIterator args = new ArgIterator( __arglist ); Object o = args.GetNextArgType(); }
public MyStruct SumAndCount(int a, int b, __arglist) { Console.WriteLine("This type: " + this.GetType().ToString()); MyStruct t = new MyStruct(); ArgIterator args = new ArgIterator(__arglist); t.x += (a + b); t.y += args.GetRemainingCount(); while (args.GetRemainingCount() > 0) { if (args.GetNextArgType().Equals(typeof(int).TypeHandle)) { int N = __refvalue(args.GetNextArg(), int); Console.WriteLine("int value is " + N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(byte).TypeHandle)) { byte N = __refvalue(args.GetNextArg(), byte); Console.WriteLine("byte value is " + N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(short).TypeHandle)) { short N = __refvalue(args.GetNextArg(), short); Console.WriteLine("short value is " + N); t.x = t.x + N; } else if (args.GetNextArgType().Equals(typeof(long).TypeHandle)) { TypedReference tr = args.GetNextArg(); Interlocked.Increment(ref __refvalue(tr, long)); long N = __refvalue(tr, long); Console.WriteLine("long value is " + N); t.x = t.x + (int)(N % 57); } else if (args.GetNextArgType().Equals(typeof(float).TypeHandle)) { float N = __refvalue(args.GetNextArg(), float); Console.WriteLine("float value is " + N); t.x = t.x + (int)N; } else if (args.GetNextArgType().Equals(typeof(double).TypeHandle)) { double N = __refvalue(args.GetNextArg(), double); Console.WriteLine("double value is " + N); t.x = t.x + (int)N; } else if (args.GetNextArgType().Equals(typeof(Struct1).TypeHandle)) { Struct1 N = __refvalue(args.GetNextArg(), Struct1); Console.WriteLine("Struct1 value is " + N.x); t.x = t.x + N.x; } else { throw new Exception(); } } return(t); }