static void MoreHappened() { TestLogger.Log("More happened"); }
private static void GenericCallToGenericModifier <T>(T t, Modifier <T> f) { TestLogger.Log(t.ToString()); GenericModifier <T>(t, f); TestLogger.Log(t.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 ReplaceClassInPlace(ref Class c) { c = new Class(42); TestLogger.Log(c.ToString()); }
public static void ModifyIntCopy(int i) { i++; TestLogger.Log(i); }
public static void ModifyStructCopy(Struct s) { s.Modify(); TestLogger.Log(s.ToString()); }
public new void S() { TestLogger.Log("CDerived3::S"); }
public void M(SSimple t) { t.S(); TestLogger.Log(t.ToString()); TestLogger.Log(t.GetType().Name); }
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()); } }
static void Main() { { TestLogger.Log("Testing Boolean.ToString..."); TestLogger.Log(true.ToString()); TestLogger.Log(false.ToString()); } { var result = false; TestLogger.Log("Testing Boolean.TryParse..."); TestLogger.Log(Boolean.TryParse("True", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("true", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("TRUE", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("Frue", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("false", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("FALSE", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("1", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("0", out result).ToString()); TestLogger.Log(result); TestLogger.Log(Boolean.TryParse("Bad", out result).ToString()); TestLogger.Log(result); } { TestLogger.Log("Testing DateTime.ToString..."); var time = new DateTime(1979, 7, 31, 10, 25, 0); TestLogger.Log(time.ToString()); } { TestLogger.Log("Testing String.Empty..."); TestLogger.Log(String.Empty.Length); } { TestLogger.Log("Testing String.Equals..."); TestLogger.Log(String.Equals("True", "True")); TestLogger.Log(String.Equals("True", "true")); TestLogger.Log(String.Equals("True", "False")); TestLogger.Log(String.Equals("True", "false")); TestLogger.Log(String.Equals("True", "True", StringComparison.Ordinal)); TestLogger.Log(String.Equals("True", "true", StringComparison.Ordinal)); TestLogger.Log(String.Equals("True", "False", StringComparison.Ordinal)); TestLogger.Log(String.Equals("True", "false", StringComparison.Ordinal)); TestLogger.Log(String.Equals("True", "True", StringComparison.OrdinalIgnoreCase)); TestLogger.Log(String.Equals("True", "true", StringComparison.OrdinalIgnoreCase)); TestLogger.Log(String.Equals("True", "False", StringComparison.OrdinalIgnoreCase)); TestLogger.Log(String.Equals("True", "false", StringComparison.OrdinalIgnoreCase)); } { TestLogger.Log("Testing String.ToUpper..."); TestLogger.Log("True".ToUpper()); TestLogger.Log("true".ToUpper()); TestLogger.Log("TRUE".ToUpper()); } { TestLogger.Log("Testing String.ToUpper..."); TestLogger.Log("True".ToLower()); TestLogger.Log("true".ToLower()); TestLogger.Log("TRUE".ToLower()); } { TestLogger.Log("Testing String.IsNullOrEmpty..."); TestLogger.Log(String.IsNullOrEmpty(String.Empty)); TestLogger.Log(String.IsNullOrEmpty(null)); TestLogger.Log(String.IsNullOrEmpty("")); TestLogger.Log(String.IsNullOrEmpty("a")); } { TestLogger.Log("Testing String.Format..."); TestLogger.Log(String.Format("0")); TestLogger.Log(String.Format("0", "arg0")); TestLogger.Log(String.Format("0", "arg0", "arg1")); TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2", "arg3")); TestLogger.Log(String.Format("0", "arg0", "arg1", "arg2", "arg3", "arg4")); try { TestLogger.Log(String.Format("1 {0}")); } catch (Exception e) { TestLogger.LogException(e); } TestLogger.Log(String.Format("1 {0}", "arg0")); TestLogger.Log(String.Format("1 {0}", "arg0", "arg1")); TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2", "arg3")); TestLogger.Log(String.Format("1 {0}", "arg0", "arg1", "arg2", "arg3", "arg4")); try { TestLogger.Log(String.Format("2 {0} {1}")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("2 {0} {1}", "arg0")); } catch (Exception e) { TestLogger.LogException(e); } TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1")); TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2", "arg3")); TestLogger.Log(String.Format("2 {0} {1}", "arg0", "arg1", "arg2", "arg3", "arg4")); try { TestLogger.Log(String.Format("3 {0} {1} {2}")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1")); } catch (Exception e) { TestLogger.LogException(e); } TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2", "arg3")); TestLogger.Log(String.Format("3 {0} {1} {2}", "arg0", "arg1", "arg2", "arg3", "arg4")); try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2")); } catch (Exception e) { TestLogger.LogException(e); } TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2", "arg3")); TestLogger.Log(String.Format("4 {0} {1} {2} {3}", "arg0", "arg1", "arg2", "arg3", "arg4")); try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2")); } catch (Exception e) { TestLogger.LogException(e); } try { TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2", "arg3")); } catch (Exception e) { TestLogger.LogException(e); } TestLogger.Log(String.Format("5 {0} {1} {2} {3} {4}", "arg0", "arg1", "arg2", "arg3", "arg4")); TestLogger.Log(String.Format("Skip {0} {1}", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("Skip {0} {2}", "arg0", "arg1", "arg2")); TestLogger.Log(String.Format("Skip {1} {2}", "arg0", "arg1", "arg2")); } { TestLogger.Log("Testing String.Split..."); foreach (var item in "a,b,c,d,efghi,j".Split(',')) { TestLogger.Log(item); } } { TestLogger.Log("Testing String.Substring..."); string a = "1234567890"; TestLogger.Log(a.Substring(2, 5)); } { TestLogger.Log("Testing String.Join..."); TestLogger.Log(string.Join(",", new string[] { "a", "b", "c", "def", "ghi" })); } { TestLogger.Log("Testing IndexOf(str)..."); TestLogger.Log("abcdefg".IndexOf("abcdefg")); TestLogger.Log("abcdefg".IndexOf("abc")); TestLogger.Log("abcdefg".IndexOf("bcd")); TestLogger.Log("abcdefg".IndexOf("efg")); TestLogger.Log("abcdefg".IndexOf("")); TestLogger.Log("abcdefg".IndexOf("___")); try { TestLogger.Log("abcdefg".IndexOf(null)); } catch (ArgumentNullException) { TestLogger.Log("ArgumentNullException"); } TestLogger.Log("Testing IndexOf(char)..."); TestLogger.Log("abcdefg".IndexOf('A')); TestLogger.Log("abcdefg".IndexOf('z')); TestLogger.Log("abcdefg".IndexOf('d')); TestLogger.Log("abcdefg".IndexOf('g')); TestLogger.Log("abcdefg".IndexOf('a')); TestLogger.Log("Testing IndexOf scenario..."); const char Separator = '|'; const string TestStr = "This|is|a|test"; int invalidIndex = TestStr.IndexOf(Separator); TestLogger.Log(invalidIndex); int validIndex = TestStr.IndexOf(Separator.ToString()); TestLogger.Log(validIndex); } { TestLogger.Log("Testing LastIndexOf(string)..."); TestLogger.Log("abcdefgabcdefg".LastIndexOf("abcdefg")); TestLogger.Log("abcdefgabcdefg".LastIndexOf("abc")); TestLogger.Log("abcdefgabcdefg".LastIndexOf("bcd")); TestLogger.Log("abcdefgabcdefg".LastIndexOf("efg")); TestLogger.Log("abcdefgabcdefg".LastIndexOf("") + 100); TestLogger.Log("".LastIndexOf("") + 200); TestLogger.Log("a".LastIndexOf("") + 300); TestLogger.Log("abcdefgabcdefg".LastIndexOf("___")); try { TestLogger.Log("abcdefgabcdefg".LastIndexOf(null)); } catch (ArgumentNullException) { TestLogger.Log("ArgumentNullException"); } TestLogger.Log("Testing LastIndexOf(char)..."); TestLogger.Log("abcdefgabcdefg".LastIndexOf('A')); TestLogger.Log("abcdefgabcdefg".LastIndexOf('z')); TestLogger.Log("abcdefgabcdefg".LastIndexOf('d')); TestLogger.Log("abcdefgabcdefg".LastIndexOf('g')); TestLogger.Log("abcdefgabcdefg".LastIndexOf('a')); } { TestLogger.Log("Testing basic string append..."); StringBuilder sb = new StringBuilder(); sb.Append("a"); sb.Append("b"); TestLogger.Log(sb.ToString()); } { var mixedArray = new Dummy[3]; mixedArray[0] = new Dummy(); mixedArray[1] = null; TestLogger.Log("Testing char to string..."); TestLogger.Log(('c').ToString()); TestLogger.Log("Testing special append..."); StringBuilder sb = new StringBuilder(); sb.Append("a"); sb.Append(""); sb.Append((string)null); sb.Append(1); sb.Append(2.0); sb.Append(mixedArray[0]); // object with tostring sb.Append(mixedArray[1]); // null sb.Append(mixedArray[2]); // undefined sb.Append('c'); sb.Append("b"); TestLogger.Log(sb.ToString()); } { TestLogger.Log("Testing nested append..."); StringBuilder sb = new StringBuilder(); sb.Append("a"); StringBuilder nested = new StringBuilder(); nested.Append("{"); nested.Append("b"); nested.Append("}"); sb.Append(nested.ToString()); sb.Append("|"); sb.Append(nested); sb.Append("c"); TestLogger.Log(sb.ToString()); } }
public static void Main() { { TestLogger.Log("Testing Void -> Void..."); var a = new A() { i = 3 }; var d = new Test(a.One); d(); } { TestLogger.Log("Testing Void -> Int..."); var a = new A() { i = 3 }; var d = new TestInt(a.OneInt); TestLogger.Log(d()); } { TestLogger.Log("Testing Int -> Int..."); var a = new A() { i = 3 }; var d = new TestIntInt(a.OneIntInt); TestLogger.Log(d(5)); } { TestLogger.Log("Testing Void -> String..."); var a = new A() { i = 3 }; var d = new TestString(a.OneString); TestLogger.Log(d()); } { TestLogger.Log("Testing String -> String..."); var a = new A() { i = 3 }; var d = new TestStringString(a.OneStringString); TestLogger.Log(d("5")); } { TestLogger.Log("Testing String -> String static..."); var d = new TestStringString(A.StaticStringString); TestLogger.Log(d("2")); } { TestLogger.Log("Testing simple delegate hash..."); var a1 = new A() { i = 3 }; var a2 = new A() { i = 5 }; var d1 = new TestStringString(a1.OneStringString); var d2 = new TestStringString(a2.OneStringString); var d3 = new TestString(a1.OneString); // Remember: Hash code for simple delegates is based on delegate type alone TestLogger.Log(d1.GetHashCode() == d1.GetHashCode()); TestLogger.Log(d1.GetHashCode() == d2.GetHashCode()); TestLogger.Log(d1.GetHashCode() != d3.GetHashCode()); } { TestLogger.Log("Testing combined delegates..."); var a1 = new A() { i = 3 }; var a2 = new A() { i = 5 }; var d1 = new TestStringString(a1.OneStringString); var d2 = new TestStringString(a2.OneStringString); var d3 = new TestStringString(a1.TwoStringString); var d4 = new TestStringString(a1.ThreeStringString); var d5 = (TestStringString)Delegate.Combine(d1, d2); var d6 = (TestStringString)Delegate.Combine(d3, d5); var d7 = (TestStringString)Delegate.Combine(d6, d4); TestLogger.Log(d7("7")); TestLogger.Log("Testing combined delegate hash..."); TestLogger.Log(d7.GetHashCode() == d7.GetHashCode()); TestLogger.Log(d7.GetHashCode() != d6.GetHashCode()); TestLogger.Log("Testing removing delegates..."); var d8 = (TestStringString)Delegate.Remove(d7, d5); TestLogger.Log(d8("8")); var d9 = (TestStringString)Delegate.Remove(d7, d2); TestLogger.Log(d9("9")); var d10 = (TestStringString)Delegate.Combine(d3, d2); var d11 = (TestStringString)Delegate.Remove(d7, d10); TestLogger.Log(d11("11")); } { TestLogger.Log("Testing virtual delegate..."); var a = new A() { i = 3 }; var d1 = new TestString(a.Virtual); TestLogger.Log(d1()); var b = (A) new B() { i = 7 }; var d2 = new TestString(b.Virtual); TestLogger.Log(d2()); } { TestLogger.Log("Testing delegate with captured variable..."); var outer = 7; FromTo(1, 3, delegate(int i) { TestLogger.Log(outer); TestLogger.Log(i); return(outer * 4); }); FromTo(1, 3, i => { TestLogger.Log(outer); TestLogger.Log(i); return(outer * 4); }); } { TestLogger.Log("Testing delegate with captured reference variable..."); for (var i = 1; i <= 3; i++) { Prepare(delegate { TestLogger.Log(i); }); } Call(); } { TestLogger.Log("Testing delegate with captured value variable..."); for (var i = 1; i <= 3; i++) { var j = i; Prepare(delegate { TestLogger.Log(j); }); } Call(); } { TestLogger.Log("Testing event registering, triggering and unregestering..."); SomethingHappened += delegate { TestLogger.Log("Something happened."); }; if (SomethingHappened != null) { SomethingHappened(); } SomethingHappened += MoreHappened; if (SomethingHappened != null) { SomethingHappened(); } SomethingHappened -= MoreHappened; if (SomethingHappened != null) { SomethingHappened(); } } { TestLogger.Log("Testing delegates of higher-kinded type over polymorphic methods..."); var polyint = new Poly <int>(3); var polystr = new Poly <string>("four"); StringToString f = polyint.M <string>; TestLogger.Log(f("six")); IntToString g = polyint.M <int>; TestLogger.Log(g(7)); StringToString h = polystr.M <string>; TestLogger.Log(h("eight")); IntToString i = polystr.M <int>; TestLogger.Log(i(9)); } #if false { TestLogger.Log("Testing BeginInvoke/EndInvoke..."); Func <int, int, int> d = (x, y) => { TestLogger.Log("delegate called"); return(x + y); }; AsyncCallback cb = ar2 => { if (ar2.IsCompleted) { TestLogger.Log("completed asyncronously"); } else { TestLogger.Log("not completed asyncronously"); } TestLogger.Log(d.EndInvoke(ar2)); }; TestLogger.Log("invoking"); System.Diagnostics.Debugger.Break(); var ar = d.BeginInvoke(3, 7, cb, null); if (ar.IsCompleted) { TestLogger.Log("completed immediatly"); } else { TestLogger.Log("not completed immediatly"); } if (ar.CompletedSynchronously) { TestLogger.Log("completed syncronously"); TestLogger.Log(d.EndInvoke(ar)); } TestLogger.Log("done"); } #endif }
public static string StaticStringString(string s) { TestLogger.Log("StaticStringString invoked"); return("1" + s); }
protected void Log(string s) { TestLogger.Log(s + " invoked"); TestLogger.Log("i: " + i.ToString()); }
public void S() { TestLogger.Log("SSimple::S"); }
void IImplicit.M(int i) { TestLogger.Log("BaseImplicit::Implicit.M(int)"); }
private static void Unary(int a, int b) { TestLogger.Log(a + ", " + b); }
void IImplicit.M(bool b) { TestLogger.Log("BaseImplicit::Implicit.M(bool)"); }
public static void ModifyIntInPlace(ref int i) { i++; TestLogger.Log(i); }
public void M(string s) { TestLogger.Log("BaseImplicit::M(string)"); }
public static void ModifyStructInPlace(ref Struct s) { s.Modify(); TestLogger.Log(s.ToString()); }
public void M(float f) { TestLogger.Log("BaseImplicit::M(float)"); }
public static void ModifyClassInPlace(ref Class c) { c.Modify(); TestLogger.Log(c.ToString()); }
void IImplicit.M(bool b) { TestLogger.Log("DerivedImplicit::Implicit.M(bool)"); }
private static void GenericModifier <T>(T t, Modifier <T> f) { TestLogger.Log(t.ToString()); f(t); TestLogger.Log(t.ToString()); }
public new void M(string s) { TestLogger.Log("DerivedImplicit::M(string)"); }
public string Instance() { TestLogger.Log("Instance invoked"); return(v.ToString()); }
static void Main() { { TestLogger.Log("Testing basic interface methods..."); ISimple s1 = new CSimple(); s1.S(); ISimple s2 = new SSimple(); s2.S(); ISimple s3 = new CDerived1(); s3.S(); ISimple s4 = new CDerived2(); s4.S(); ISimple s5 = new CDerived3(); s5.S(); } { TestLogger.Log("Testing virtuals..."); object c = new CChild(); var ia = c as IA; var d = c as Dummy; if (d != null) { TestLogger.Log("Invalid casting"); } TestLogger.Log(5.ToString()); TestLogger.Log(ia.A()); TestLogger.Log(((CA)c).Virtual()); TestLogger.Log(((CChild)c).VirtualDontOverride()); TestLogger.Log(((IB)c).A()); TestLogger.Log(((IAB)c).B()); TestLogger.Log((new CGrandChild()).Virtual()); // TestLogger.Log(((IAB)c).A()); // ambiguous at compile-time } { TestLogger.Log("Testing constrained call on 'naked' type parameter..."); var cic = new ConstrainedInterface <CSimple>(); cic.M(new CSimple()); var cis = new ConstrainedInterface <SSimple>(); cis.M(new SSimple()); var cc = new ConstrainedClass <CSimple>(); cc.M(new CSimple()); var cs = new ConstrainedStruct <SSimple>(); cs.M(new SSimple()); var kc = new KnownClass(); kc.M(new CSimple()); var ks = new KnownStruct(); ks.M(new SSimple()); } { TestLogger.Log("Testing implicit interface implementations..."); var b = new BaseImplicit(); var d = new DerivedImplicit(); ((IImplicit)b).M(1); ((IImplicit)b).M(false); ((IImplicit)b).M("three"); ((IImplicit)b).M(4.0f); ((IImplicit)d).M(2); ((IImplicit)d).M(true); ((IImplicit)d).M("five"); ((IImplicit)d).M(6.0f); } }
public virtual void Test() { TestLogger.Log("BaseClass::Test"); }
public ProxiedBase() { TestLogger.Log("ProxiedBase::.ctor()"); }