public override string ToString() { return("WrappedStruct(" + s.ToString() + ")"); }
public static void Main() { { var i = 3; var o = (object)i; var o2 = (object)7; TestLogger.Log("Testing instance methods on unboxed int..."); TestLogger.Log(i + 9); TestLogger.Log(Math.Max(i, 9)); TestLogger.Log((int)i.GetTypeCode()); TestLogger.Log("Testing virtual method on unboxed int..."); TestLogger.Log(i.ToString()); TestLogger.Log("Testing virtual method on boxed int..."); TestLogger.Log(o.ToString()); TestLogger.Log("Testing interface call on unboxed int..."); TestLogger.Log(i.CompareTo(o)); TestLogger.Log(i.CompareTo(o2)); } { TestLogger.Log("Testing boxing of value field..."); var s = new Struct(5); var o = (object)s.v; TestLogger.Log(o.ToString()); TestLogger.Log("Testing boxing of value element..."); var a = new int[3] { 1, 2, 3 }; var o2 = (object)a[1]; TestLogger.Log(o2.ToString()); } { var s = new Struct(3); var o = (object)s; var o2 = (object)new Struct(7); TestLogger.Log("Testing instance methods on unboxed struct..."); TestLogger.Log(s.Instance()); TestLogger.Log("Testing virtual method on unboxed struct..."); TestLogger.Log(s.ToString()); TestLogger.Log("Testing virtual method on boxed struct..."); TestLogger.Log(o.ToString()); TestLogger.Log("Testing interface call on unboxed struct..."); TestLogger.Log(s.CompareTo(o)); TestLogger.Log(s.CompareTo(o2)); } { var c = new Class(3); var o = (object)c; var o2 = (object)new Class(7); TestLogger.Log("Testing instance methods on class..."); TestLogger.Log(c.Instance()); TestLogger.Log("Testing virtual method on class..."); TestLogger.Log(c.ToString()); TestLogger.Log("Testing virtual method on cast class..."); TestLogger.Log(o.ToString()); TestLogger.Log("Testing interface call on class..."); TestLogger.Log(c.CompareTo(o)); TestLogger.Log(c.CompareTo(o2)); } { var i = 3; TestLogger.Log("Testing passing int by value..."); TestLogger.Log(i); ModifyIntCopy(i); TestLogger.Log(i); TestLogger.Log("Testing passing int by ref..."); ModifyIntInPlace(ref i); TestLogger.Log(i); } { var s = new Struct(3); TestLogger.Log("Testing modifying struct in place..."); TestLogger.Log(s.ToString()); s.Modify(); TestLogger.Log(s.ToString()); TestLogger.Log("Testing passing struct by value..."); ModifyStructCopy(s); TestLogger.Log(s.ToString()); TestLogger.Log("Testing passing struct by boxed value..."); ModifyStructBoxed(s); TestLogger.Log(s.ToString()); TestLogger.Log("Testing passing struct by ref value..."); ModifyStructInPlace(ref s); TestLogger.Log(s.ToString()); TestLogger.Log("Testing replacing struct in place..."); ReplaceStructInPlace(ref s); TestLogger.Log(s.ToString()); } { var c = new Class(3); TestLogger.Log("Testing modifying class in place..."); TestLogger.Log(c.ToString()); c.Modify(); TestLogger.Log(c.ToString()); TestLogger.Log("Testing passing class..."); ModifyClass(c); TestLogger.Log(c.ToString()); TestLogger.Log("Testing passing class as object..."); ModifyClassAsObject(c); TestLogger.Log(c.ToString()); TestLogger.Log("Testing passing class by ref value..."); ModifyClassInPlace(ref c); TestLogger.Log(c.ToString()); TestLogger.Log("Testing replacing class in place..."); ReplaceClassInPlace(ref c); TestLogger.Log(c.ToString()); } { var s = new Struct(3); TestLogger.Log("Testing static field..."); f = s; f.Modify(); TestLogger.Log(s.ToString()); TestLogger.Log(f.ToString()); } { var s = new Struct(3); TestLogger.Log("Testing returning self..."); var self = s.ReturnSelf(); self.Modify(); TestLogger.Log(self.ToString()); TestLogger.Log(s.ToString()); } { TestLogger.Log("Testing wrapping..."); var w = new WrappedStruct(new Struct(5)); TestLogger.Log(w.ToString()); } { TestLogger.Log("Testing generic struct of ref type..."); var g = new GenericStruct <string>(); g.v = "a"; TestLogger.Log(g.v); Call(g, "b"); TestLogger.Log(g.v); } { TestLogger.Log("Testing generic struct of struct..."); var g = new GenericStruct <Struct>(); g.v = new Struct(1); TestLogger.Log(g.v.ToString()); g.v.Modify(); TestLogger.Log(g.v.ToString()); Call(g, new Struct(9)); TestLogger.Log(g.v.ToString()); } { TestLogger.Log("Testing generic method on struct..."); var arr = new Struct[2] { new Struct(1), new Struct(3) }; GenericMethod.TestLoop(arr); } { TestLogger.Log("Testing generic method on ref type..."); var arr = new Class[2] { new Class(1), new Class(3) }; GenericMethod.TestLoop(arr); } { TestLogger.Log("Testing generic boxing..."); var i = 3; GenericBoxer(i); var str = "test"; GenericBoxer(str); var s = new GenericStruct <int>() { v = 7 }; GenericBoxer(s); var c = new GenericClass <int>() { v = 9 }; GenericBoxer(c); } { TestLogger.Log("Testing generic return..."); var i = 3; var i2 = GenericCopier(i, a => a + 1); TestLogger.Log(i2.ToString()); var str = "test"; var str2 = GenericCopier(str, a => a + "done"); TestLogger.Log(str2.ToString()); var s = new GenericStruct <int>() { v = 7 }; var s2 = GenericCopier(s, a => new GenericStruct <int>() { v = a.v + 1 }); TestLogger.Log(s2.ToString()); var c = new GenericClass <int>() { v = 9 }; var c2 = GenericCopier(c, a => new GenericClass <int>() { v = a.v + 1 }); TestLogger.Log(c2.ToString()); } { TestLogger.Log("Testing generic modification..."); var i = 3; GenericModifier(i, a => a++); TestLogger.Log(i.ToString()); var str = "test"; GenericModifier(str, a => a = "done"); TestLogger.Log(str.ToString()); var s = new GenericStruct <int>() { v = 7 }; GenericModifier(s, a => a.v++); TestLogger.Log(s.ToString()); GenericCallToGenericModifier(s, a => a.v++); TestLogger.Log(s.ToString()); var c = new GenericClass <int>() { v = 9 }; GenericModifier(c, a => a.v++); TestLogger.Log(c.ToString()); GenericCallToGenericModifier(c, a => a.v++); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing stack non-interferance..."); var a = 3; var b = 7; var c = 10; var x = true; var y = true; TestLogger.Log(String.Format("a = {0}, b = {1}, c = {2}", a, b, c)); TestLogger.Log(AddArgs(a, x ? a++ : b++, y ? a++ : c++).ToString()); TestLogger.Log(String.Format("a = {0}, b = {1}, c = {2}", a, b, c)); } { TestLogger.Log("Testing integer equalities..."); var one = 1; var a = 1; var two = 2; TestLogger.Log(one.Equals(one)); TestLogger.Log(one.Equals(a)); TestLogger.Log(one.Equals(two)); TestLogger.Log(a.Equals(one)); TestLogger.Log(two.Equals(one)); var boxedOne = (object)one; var boxedA = (object)a; var boxedTwo = (object)two; TestLogger.Log("Testing boxed integer equalities..."); TestLogger.Log(boxedOne.Equals(boxedOne)); TestLogger.Log(boxedOne.Equals(boxedA)); TestLogger.Log(boxedOne.Equals(boxedTwo)); TestLogger.Log(boxedA.Equals(boxedOne)); TestLogger.Log(boxedTwo.Equals(boxedOne)); TestLogger.Log("Testing reference equalities..."); var five = new Class(5); Class six = new Class(6); Class fiveAsWell = new Class(5); Class sixAsWell = six; TestLogger.Log(five.Equals(five)); TestLogger.Log(five.Equals(six)); TestLogger.Log(five.Equals(fiveAsWell)); TestLogger.Log(six.Equals(sixAsWell)); TestLogger.Log(six.Equals(five)); TestLogger.Log(fiveAsWell.Equals(five)); TestLogger.Log(sixAsWell.Equals(six)); } }
public static void ReplaceStructInPlace(ref Struct s) { s = new Struct(42); TestLogger.Log(s.ToString()); }
public static void ModifyStructInPlace(ref Struct s) { s.Modify(); TestLogger.Log(s.ToString()); }
public static void ModifyStructCopy(Struct s) { s.Modify(); TestLogger.Log(s.ToString()); }
public override string ToString() { return("Class() { s = " + s.ToString() + ", i = " + i.ToString() + ", str = " + (str == null ? "null" : str) + ", o = " + (o == null ? "null" : o.ToString()) + ", c = " + ((int)c).ToString() + ", e = " + ((int)e).ToString() + " }"); }
static void Main() { { TestLogger.Log("Testing static initialization..."); TestLogger.Log(si.ToString()); TestLogger.Log(sstr == null ? "null" : sstr); TestLogger.Log(((int)se).ToString()); TestLogger.Log(sc == null ? "null" : sc.ToString()); TestLogger.Log(ss.ToString()); } { TestLogger.Log("Testing struct initialization..."); var s = new Struct(); TestLogger.Log(s.ToString()); } { TestLogger.Log("Testing struct constructor..."); var s = new Struct(7.3, 12.11); TestLogger.Log(s.ToString()); } { TestLogger.Log("Testing class initialization..."); var c = new Class(); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing class constructor..."); var c = new Class(7, "test"); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing derived initialization..."); var c = new DerivedClass(); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing derived constructor..."); var c = new DerivedClass(7, "test", 12); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing generic initialization over int..."); var c = new GenericClass <int>(); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing generic constructor over int..."); var c = new GenericClass <int>(7); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing generic initialization over string..."); var c = new GenericClass <string>(); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing generic constructor over string..."); var c = new GenericClass <string>("test"); TestLogger.Log(c.ToString()); } { TestLogger.Log("Testing construction of generic parameter with int..."); var c = new GenericConstructorTest <int>(); TestLogger.Log(c.ToString()); TestLogger.Log(c.GenericBox().ToString()); } { TestLogger.Log("Testing construction of generic parameter with class..."); var c = new GenericConstructorTest <Class>(); TestLogger.Log(c.ToString()); TestLogger.Log(c.GenericBox().ToString()); } }