public void FieldsTest() { var sc2 = new SomeClass2(); var sc2W = sc2.Wrap <ISomeClass2>(); Assert.NotNull(sc2W.field); Assert.AreEqual("Hello", sc2W.field.Prop1); sc2W.field = new SomeClass1() { Prop1 = "World" }.Wrap <ISomeClass1>(); Assert.AreEqual("World", sc2W.field.Prop1); Assert.AreEqual("World", sc2W.Property.Prop1); Assert.AreEqual("World", sc2W.Method().Prop1); sc2W.Method2(new SomeClass1() { Prop1 = "Value1" }.Wrap <ISomeClass1>()); Assert.AreEqual("Value1", sc2W.Property.Prop1); var old = sc2W.Method3(new SomeClass1() { Prop1 = "Value2" }.Wrap <ISomeClass1>()); Assert.AreEqual("Value1", old.Prop1); Assert.AreEqual("Value2", sc2W.Property.Prop1); }
public void FactMethodName2() { var mockedTmp = new Mock <ITmp>(); var testScheduler = new TestScheduler(); var temp = new SomeClass2(mockedTmp.Object, testScheduler); const int c = 1; var eventArgs1 = new MyEventArgs(1); var eventArgs2 = new MyEventArgs(2); var results = testScheduler.CreateObserver <MyEventArgs>(); temp.Raw().Select(ep => ep.EventArgs).Subscribe(results); testScheduler.Schedule(TimeSpan.FromTicks(1000), () => mockedTmp.Raise(tmp => tmp.tmpEvent += null, eventArgs1)); testScheduler.Schedule(TimeSpan.FromTicks(2000), () => mockedTmp.Raise(tmp => tmp.tmpEvent += null, eventArgs2)); testScheduler.Start(); results.Messages.AssertEqual( OnNext(1000 + c, eventArgs1), OnNext(2000 + c, eventArgs2)); }
public void InvokesVirtualMethodAs() { var t2 = new SomeClass2(); var t3 = new SomeClass3(); var method = typeof(SomeClass2).Method("SetP2P3", typeof(string), typeof(string)); Assert.Null(method.InvokerAs <Func <SomeClass2, string, string, object> >()(t2, "t1", "t2")); Assert.Equal("t1", t2.P2); Assert.Equal("t2", t2.P3); Assert.Null(method.InvokerAs <Func <object, string, object, object> >()(t2, "t1!", "t2!")); Assert.Equal("t1!", t2.P2); Assert.Null(method.InvokerAs <Func <SomeClass2, string, string, object> >()(t3, "t1", "t2")); Assert.Equal("t1_", t3.P2); Assert.Equal("t2_", t3.P3); Assert.Null(method.InvokerAs <Func <SomeClass2, string, string, object> >()(t3, "t1!", "t2!")); Assert.Equal("t1!_", t3.P2); Assert.Equal("t2!_", t3.P3); var method2 = typeof(SomeClass3).Method("SetP2P3", typeof(string), typeof(string)); Assert.Null(method2.InvokerAs <Func <SomeClass2, string, string, object> >()(t3, "t11", "t22")); Assert.Equal("t11_", t3.P2); Assert.Equal("t22_", t3.P3); Assert.Null(method2.InvokerAs <Func <SomeClass2, string, string, object> >()(t3, "t11!", "t22!")); Assert.Equal("t11!_", t3.P2); Assert.Equal("t22!_", t3.P3); }
public void SomeFunction() { SomeClass2 someClass2 = new SomeClass2(); SomeClass3 someClass3 = new SomeClass3(); // Note: SomeClass41 is not accessable! //SomeClass4.SomeClass41 someClass41 = new SomeClass4.SomeClass41(); SomeClass4.SomeClass42 someClass42 = new SomeClass4.SomeClass42(); SomeClass4.SomeClass43 someClass43 = new SomeClass4.SomeClass43(); // Note: SomeClass51 is not accessable! //SomeClass5.SomeClass51 someClass51 = new SomeClass5.SomeClass51(); SomeClass5.SomeClass52 someClass52 = new SomeClass5.SomeClass52(); SomeClass5.SomeClass53 someClass53 = new SomeClass5.SomeClass53(); SomeClass6 someClass6 = new SomeClass6(); someClass6.A = 10; // Note: B Property is not Accessable! //someClass6.B = 20; // Note: C Property is not Accessable! //someClass6.C = 30; someClass6.D = 40; someClass6.E = 50; }
public void GetDeclaredTypeWorks() { IList <int> v1 = new List <int>(); SomeClass1 t = new SomeClass2(); Assert.Equal(typeof(IList <int>), TypeEx.TypeOf(v1)); Assert.Equal(typeof(Dictionary <string, double>), TypeEx.TypeOf((Dictionary <string, double>)null)); Assert.Equal(typeof(SomeClass1), TypeEx.TypeOf(t)); }
public void InvokesPrivateMethodInvoker() { var t2 = new SomeClass2(); var method = typeof(SomeClass2).Method("SetP2P3Test", typeof(string), typeof(string)); Assert.Null(method.Invoker()(t2, "t1", "t2")); Assert.Equal("t1", t2.P2); Assert.Equal("t2", t2.P3); }
void Start() { SomeClass2 myClass = new SomeClass2(); // In order to use this method you must // tell the method what type to replace // 'T' with. myClass.GenericMethod <int>(5); }
static void Main(string[] args) { var class1 = new SomeClass1(); class1.Action = new Class1.Action(); var class2 = new SomeClass2(); class2.Action = new Class2Action(); }
public void SetterThrowsIfWrongType() { var c = new SomeClass1(); var d = new SomeClass2(); Assert.Throws <InvalidCastException>( () => typeof(SomeClass2).Field("_f1").SetterAs <Action <object, object> >()(c, 123)); Assert.Throws <InvalidCastException>( () => typeof(SomeClass2).Field("_f1").SetterAs <Action <object, object> >()(d, "te")); }
public void InvokesIntMethodInvoker() { var t2 = new SomeClass2(); var t3 = new SomeClass3(); var method = typeof(SomeClass2).Method("GetF1"); var invoker = method.Invoker(); Assert.Equal(11, invoker(t2)); Assert.Equal(11, invoker(t3)); }
public void InvokesPrivateMethodAs() { var t2 = new SomeClass2(); var method = typeof(SomeClass2).Method("SetP2P3Test", typeof(string), typeof(string)); Assert.Null(method.InvokerAs <Func <object, object, object, object> >()(t2, "t1", "t2")); Assert.Equal("t1", t2.P2); Assert.Equal("t2", t2.P3); Assert.Null(method.InvokerAs <Func <object, string, string, object> >()(t2, "t1!", "t2!")); Assert.Equal("t1!", t2.P2); Assert.Equal("t2!", t2.P3); }
public void RefTest() { var sc2 = new SomeClass2(); var sc2W = sc2.Wrap <ISomeClass2>(); ISomeClass1 value = new SomeClass1().Wrap <ISomeClass1>(); sc2W.Method6(ref value); Assert.AreEqual("Method6", value.Prop1); Assert.AreEqual("Hello", sc2W.Method7(ref value)); Assert.AreEqual("Method7", value.Prop1); }
public void OutTest() { var sc2 = new SomeClass2(); var sc2W = sc2.Wrap <ISomeClass2>(); ISomeClass1 value; sc2W.Method4(out value); Assert.AreEqual("Method4", value.Prop1); Assert.AreEqual("Hello", sc2W.Method5(out value)); Assert.AreEqual("Method5", value.Prop1); }
public void InvokesIntMethodAs() { var t2 = new SomeClass2(); var t3 = new SomeClass3(); var method = typeof(SomeClass2).Method("GetF1"); var invoker1 = method.InvokerAs <Func <SomeClass2, int> >(); var invoker2 = method.InvokerAs <Func <object, object> >(); Assert.Equal(11, invoker1(t2)); Assert.Equal(11, invoker2(t2)); Assert.Equal(11, invoker1(t3)); Assert.Equal(11, invoker2(t3)); }
public void TestNamedParams() { var p = 7; var expected = 7; int actual; actual = new SomeClass2(a: p).Value; Assert.AreEqual(expected, actual); actual = new SomeClass2(p).Value; Assert.AreEqual(expected, actual); actual = new SomeClass2().SumOfArray(a: p); Assert.AreEqual(expected, actual); actual = new SomeClass2().SumOfArray(p); Assert.AreEqual(expected, actual); }
public void TestOverloadedConstructorCallWithOptionalParameters() { var o1 = new SomeClass1(); Assert.AreEqual(130, o1.Value, "o1 #1"); var o12 = new SomeClass1(1); Assert.AreEqual(131, o12.Value, "o1 #2"); var o13 = new SomeClass1(1, 2); Assert.AreEqual(133, o13.Value, "o1 #3"); var o14 = new SomeClass1(a: 2); Assert.AreEqual(132, o14.Value, "o1 #4"); var o15 = new SomeClass1(a: 2, b: 3); Assert.AreEqual(135, o15.Value, "o1 #5"); var o16 = new SomeClass1(b: 3, a: 4); Assert.AreEqual(137, o16.Value, "o1 #6"); var o2 = new SomeClass2(); Assert.AreEqual(1130, o2.Value, "o2 #1"); var o22 = new SomeClass2(1); Assert.AreEqual(1131, o22.Value, "o2 #2"); var o23 = new SomeClass2(1, 2); Assert.AreEqual(1133, o23.Value, "o2 #3"); }
public NamedConstructor([BeanReference] SomeClass2 someClass) { }
public SomeClass1(SomeClass2 c2) { }
public static MyType FromSomeClass2(SomeClass2 c2) { return(new MyType(c2)); }