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) {} } }
private static void ArglistMethod (__arglist) { var iter = new ArgIterator (__arglist); for (int n = iter.GetRemainingCount (); n > 0; n--) Console.WriteLine (TypedReference.ToObject (iter.GetNextArg ())); }
// 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 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 void argit1( __arglist ) { ArgIterator args = new ArgIterator( __arglist ); int iCount = args.GetRemainingCount(); for ( int i = 0; i < iCount + 15; i++ ){ try { try { TypedReference trTypRef = args.GetNextArg(); } catch (InvalidOperationException){} if (args.GetRemainingCount()!=0) if ( args.GetRemainingCount() != (iCount - i - 1) ){ throw new Exception( "ExcErr5 ,Should have had remaining count " + (iCount - i - 1) + " but had remaining count " + args.GetRemainingCount() ); } } catch(Exception ex){ if ( i < iCount ) Console.WriteLine( "Err_argit4_00: Loop has not gone through only " + i + " arguments" ); int iRemCount = args.GetRemainingCount(); if ( iRemCount != 0 ){ Console.WriteLine( "Err_argit4_01: Should have had remaining count 0 but had remaining count " + iRemCount ); } throw ex; } } if ( args.GetRemainingCount() != 0 ){ throw new Exception( "ExcErr4 ,Should have had remaining count 0"); } }
static void TestRefValue (__arglist) { ArgIterator args = new ArgIterator (__arglist); var o = __refvalue ( args.GetNextArg (),int); for (int i = 0; i < args.GetRemainingCount (); i++) { Console.WriteLine (__refvalue (args.GetNextArg (), int)); } }
public static void DisplayNumbersOnConsole(__arglist) { ArgIterator ai = new ArgIterator(__arglist); while (ai.GetRemainingCount() > 0) { TypedReference tr = ai.GetNextArg(); Console.WriteLine(TypedReference.ToObject(tr)); } }
public void VariableArguments(__arglist) { ArgIterator argumentIterator = new ArgIterator(__arglist); for(int i = 0; i < argumentIterator.GetRemainingCount(); i++) { Console.WriteLine( __refvalue(argumentIterator.GetNextArg(), string)); } }
static void Test(int param, __arglist) { int[,] aa = new int[2, 2]; do { try { } catch (Exception) { } aa[param, Math.Min(0, 1)] = 0; } while ((new bool[2, 2])[param, param]); }
public static void argit2b (__arglist) { ArgIterator args = new ArgIterator( __arglist ); int hashcode = args.GetHashCode(); TypedReference trTypRef = args.GetNextArg(); int hashcodecompare= args.GetHashCode(); if (! hashcode.Equals(hashcodecompare)) { throw new Exception( "argit2b - 1, hashcode changed" ); } }
public static void Foo (__arglist) { System.RuntimeArgumentHandle o; { System.Action a = delegate () { o = __arglist; }; a (); } }
/// <summary> /// Arrangements the specified n and list of argument. /// A = n! / [(n_1)!.(n_2)!. ... . (n_i)!] /// </summary> /// <param name='...'> /// List of arguments /// </param> public static Int64 Arrangements(Int32 n, __arglist) { Int64 result = 1; ArgIterator iter = new ArgIterator(__arglist); Int32 argCount = iter.GetRemainingCount(); for (Int32 i = 0; i < argCount; i++) { TypedReference typedRef = iter.GetNextArg(); result *= Factorial((Int32)TypedReference.ToObject( typedRef ) ); } return Factorial(n)/result; }
//Test 1 // check whether GetHashCode returns the same value // check to see if we can use ArgIterators on any class // check ArgIterators on Arrays // test arg iterators with instance methods on normal classes public TestStruct argit1( Object[] objExpectedArr, __arglist ) { ArgIterator args = new ArgIterator( __arglist ); int hashcode = args.GetHashCode(); int iCount = args.GetRemainingCount(); Console.WriteLine( "Found "+ iCount +" arguments. " ); Object[] objArr = new Object[iCount]; for ( int i = 0; i < iCount; i++ ){ objArr[i] = TypedReference.ToObject(args.GetNextArg()); Console.WriteLine( "Object " + i + ": " + objArr[i] + " Expected: " + objExpectedArr[i] ); if ( objExpectedArr[i] == null ){ if ( objArr[i] != null ){ throw new Exception( "argit1 - 1, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } else if ( ! objArr[i].Equals( objExpectedArr[i] ) ) { throw new Exception( "argit1 - 2, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } //repeating the code above __arglist should be valid in method scope ArgIterator args2 = new ArgIterator( __arglist ); int iCount2 = args2.GetRemainingCount(); Object[] objArr2 = new Object[iCount]; for ( int i = 0; i < iCount2; i++ ){ objArr2[i] = TypedReference.ToObject(args2.GetNextArg()); Console.WriteLine( "Object " + i + ": " + objArr2[i] + " Expected: " + objExpectedArr[i] ); if ( objExpectedArr[i] == null ){ if ( objArr2[i] != null ){ throw new Exception( "argit1 - 3, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } else if ( ! objArr2[i].Equals( objExpectedArr[i] ) ) { throw new Exception( "argit1 - 4, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } int hashcodecompare= args.GetHashCode(); if (! hashcode.Equals(hashcodecompare)) { throw new Exception( "argit1 - 5, hashcode changed" ); } TestStruct Bar = new TestStruct(); Bar.foo1 = 1; Bar.foo2 = 2; return Bar; }
public static void argit2 (__arglist) { ArgIterator args = new ArgIterator( __arglist ); int hashcode = args.GetHashCode(); try{ NormClass.argit2b( __arglist( ) ); } catch (InvalidOperationException) {} int hashcodecompare= args.GetHashCode(); if (! hashcode.Equals(hashcodecompare)) { throw new Exception( "argit2 - 1, hashcode changed" ); } }
static int AddABunchOfShorts (__arglist) { int result = 0; System.ArgIterator iter = new System.ArgIterator (__arglist); int argCount = iter.GetRemainingCount(); for (int i = 0; i < argCount; i++) { System.TypedReference typedRef = iter.GetNextArg(); result += (short)TypedReference.ToObject( typedRef ); } return result; }
public static Result VtAddASecondBunchOfInts (int a, __arglist) { int result = 0; System.ArgIterator iter = new System.ArgIterator (__arglist); int argCount = iter.GetRemainingCount(); for (int i = 0; i < argCount; i++) { System.TypedReference typedRef = iter.GetNextArg(); result += (int)TypedReference.ToObject( typedRef ); } return new Result (result); }
static void Method1(ref ulong param1, __arglist) { bool a = false; while (a) { do { #pragma warning disable 1717 param1 = param1; #pragma warning restore 1717 while (a) { } } while (a); } }
/// <summary> /// Hey children - don't do that at home /// </summary> public static void Flexible(__arglist) { // Actually pretty raw access here var ai = new ArgIterator(__arglist); while (ai.GetRemainingCount() > 0) { var typeRef = ai.GetNextArg(); // Need to get the object reference from the // combined (typeref, objectref) element var obj = TypedReference.ToObject(typeRef); Debug.WriteLine(obj); } }
/// <summary> /// Write the specified color, format, arg0, arg1, arg2, arg3 and . /// </summary> /// <param name="">.</param> /// <param name="format">Format.</param> /// <param name="arg0">Arg0.</param> /// <param name="arg1">Arg1.</param> /// <param name="arg2">Arg2.</param> /// <param name="arg3">Arg3.</param> public static void Write(System.ConsoleColor color, string format, object arg0, object arg1, object arg2, object arg3, __arglist ) { ArgIterator argIterator = new ArgIterator (__arglist); int remainingCount = argIterator.GetRemainingCount (); object[] array = new object[remainingCount + 4]; array [0] = arg0; array [1] = arg1; array [2] = arg2; array [3] = arg3; for (int i = 0; i < remainingCount; i++) { TypedReference nextArg = argIterator.GetNextArg (); array [i + 4] = TypedReference.ToObject (nextArg); } var old_font = Console.ForegroundColor; Console.ForegroundColor = color; Console.Write (string.Format (format, array)); Console.ForegroundColor = old_font; }
static void X(__arglist) // 仮引数のところに __arglist を書く { // 中身のとりだしには ArgIterator 構造体を使う ArgIterator argumentIterator = new ArgIterator(__arglist); while (argumentIterator.GetRemainingCount() > 0) { object value = null; var r = argumentIterator.GetNextArg(); // 可変個引数の1個1個は TypedReference になっている var t = __reftype(r); // TypedReference から、元の型を取得 // 型で分岐して、__refvalue で値の取り出し if (t == typeof(int)) value = __refvalue(r, int); else if (t == typeof(char)) value = __refvalue(r, char); else if (t == typeof(double)) value = __refvalue(r, double); else value = __refvalue(r, string); Console.WriteLine(t.Name + ": " + value); } }
public void argit1( Object[] objExpectedArr, __arglist ) { ArgIterator args = new ArgIterator( __arglist ); int hashcode = args.GetHashCode(); int iCount = args.GetRemainingCount(); Object[] objArr = new Object[iCount]; for ( int i = 0; i < iCount; i++ ){ objArr[i] = TypedReference.ToObject(args.GetNextArg()); if ( objExpectedArr[i] == null ){ if ( objArr[i] != null ){ throw new Exception( "argit1 - 1, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } else if ( ! objArr[i].Equals( objExpectedArr[i] ) ) { throw new Exception( "argit1 - 2, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } ArgIterator args2 = new ArgIterator( __arglist ); int iCount2 = args2.GetRemainingCount(); Object[] objArr2 = new Object[iCount]; for ( int i = 0; i < iCount2; i++ ){ objArr2[i] = TypedReference.ToObject(args2.GetNextArg()); if ( objExpectedArr[i] == null ){ if ( objArr2[i] != null ){ throw new Exception( "argit1 - 3, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } else if ( ! objArr2[i].Equals( objExpectedArr[i] ) ) { throw new Exception( "argit1 - 4, __arglist[i] was null but it did not equal to objExpectedArr[i]" ); } } int hashcodecompare= args.GetHashCode(); if (! hashcode.Equals(hashcodecompare)) { throw new Exception( "argit1 - 5, hashcode changed" ); } }
public int Sub(int a, int b, __arglist) { Console.WriteLine("This type: " + this.GetType().ToString()); return (a - b); }
public static void WriteLine (string format, object arg0, object arg1, object arg2, object arg3, __arglist) { ArgIterator iter = new ArgIterator (__arglist); int argCount = iter.GetRemainingCount(); object[] args = new object [argCount + 4]; args [0] = arg0; args [1] = arg1; args [2] = arg2; args [3] = arg3; for (int i = 0; i < argCount; i++) { TypedReference typedRef = iter.GetNextArg (); args [i + 4] = TypedReference.ToObject (typedRef); } stdout.WriteLine (String.Format (format, args)); }
public System.Collections.IEnumerator GetEnumerator (__arglist) { yield return 1; }
static void Method2(double param3, long param4, __arglist) { param3 = (double)param4; }
public static void Write(String format, Object arg0, Object arg1, Object arg2, Object arg3, __arglist) { Object[] objArgs; int argCount; ArgIterator args = new ArgIterator(__arglist); //+4 to account for the 4 hard-coded arguments at the beginning of the list. argCount = args.GetRemainingCount() + 4; objArgs = new Object[argCount]; //Handle the hard-coded arguments objArgs[0] = arg0; objArgs[1] = arg1; objArgs[2] = arg2; objArgs[3] = arg3; //Walk all of the args in the variable part of the argument list. for (int i=4; i<argCount; i++) { objArgs[i] = TypedReference.ToObject(args.GetNextArg()); } Out.Write(format, objArgs); }
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; }
internal static extern Int32 printw(string format, __arglist);
void Foo (__arglist, bool b) {}