static int Main () { Derived1 d1 = new Derived1 (); Derived2 d2 = new Derived2 (); Base b1 = d1; Base b2 = d2; if (d1.Turn () != 4) return 1; if (((IVehicle)d1).Turn () != 4) return 2; if (((IVehicle)d2).Turn () != 7) return 3; if (b2.Turn () != 8) return 4; if (((IVehicle)b2).Turn () != 7) return 5; //Console.WriteLine ("TEST {0}", ((IVehicle)b2).Turn ()); return 0; }
public static int Main() { Derived1 d1 = new Derived1(); Derived1 x = d1.Method(); Derived2 d2 = new Derived2(); Derived2 y = d2.Method(); return 0; }
static private Random random = new Random(); override public object runOneIteration() { int number = random.Next(5); Cronometro cronometro = new Cronometro(); object value; var obj; if (number == 0) { obj = new Derived0(); } else if (number == 1) { obj = new Derived1(); } else if (number == 2) { obj = new Derived2(); } else if (number == 3) { obj = new Derived3(); } else { obj = new Derived4(); } cronometro.start(); for (int i = 0; i < 1000; i++) { value = obj.m(); } cronometro.stop(); this.microSeconds = this.microSeconds + cronometro.getMicroSeconds(); return(value); }
// part 3 ------------------------------------------------------------- static void FillArray(Derived1[] array) { for (int i = 0; i < array.Length; i++) { array[i] = new Derived1(); } }
static void Main(string[] args) { var derived1 = new Derived1(); var derived2 = new Derived2(); derived1.Print(); derived2.Print(); }
public void DiscriminatedUnionTwoUsingFirstSwitchActionWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.First<Base, Derived1, Derived2>(d1); bool ranFirst = false; d.Switch(v => { ranFirst = true; }, v => { ranFirst = false; }); Assert.IsTrue(ranFirst); }
static void Main(string[] args) { Base1 b = new Base1(); b.Execute(); b = new Derived1(); b.Execute(); }
public static void Main() { Derived1 <int> derv = new Derived1 <int>(); Derived2 <double> derv2 = new Derived2 <double>(); Derived2 <double> derv3 = new Derived2 <double>(); Console.ReadKey(); }
static void Main(string[] args) { Base f = new Base(); M1(f); Base f1 = new Derived1(); M1(f1); }
public static Base Create(bool condition) { if (condition) { return(Derived1.Create(1, "TEST")); } else { return(Derived2.Create(1, DateTime.Now)); } }
public static int Main() { Derived1 d1 = new Derived1(); Derived1 x = d1.Method(); Console.WriteLine(x.GetType()); // outputs Derived1 Derived2 d2 = new Derived2(); Derived2 y = d2.Method(); Console.WriteLine(y.GetType()); // outputs Derived2 }
static void Main(string[] args) { var derived1 = new Derived1(); derived1.CommonWork(); var derived2 = new Derived2(); derived2.CommonWork(); Console.Read(); }
public static void Main() { Derived1 d1 = new Derived1(); d1.Prop = 7; Console.WriteLine(d1); Base1 b1 = new Base1(); Console.WriteLine(b1); Derived2 d2 = new Derived2(); Base2 b2 = new Base2(); d2.SetTheDude(77); Console.WriteLine(d2.GetTheDude()); }
public MainPage() { this.InitializeComponent(); Derived1 d1 = new Derived1(); block.Text += d1.ToString() + Environment.NewLine; Type derivedType = typeof(Derived1); Object obj = Activator.CreateInstance(derivedType); block.Text += obj.GetType().FullName + Environment.NewLine; }
public static void Main() { Derived2 d2 = new Derived2(); Base @base = d2; Derived1 d1 = d2; @base.Print(); @base.PrintA(); @base.PrintB(); d1.Print(); d1.PrintA(); d1.PrintB(); }
static void Main() { Base baseOb = new Base(); Derived1 dOb1 = new Derived1(); Derived2 dOb2 = new Derived2(); Base baseRef; // a base class reference baseRef = baseOb; baseRef.Who(); baseRef = dOb1; baseRef.Who(); baseRef = dOb2; baseRef.Who(); }
public static void Main() { Base baseOb = new Base(); Derived1 dOb1 = new Derived1(); Derived2 dOb2 = new Derived2(); Base baseRef; // Ссылка на базовый класс. baseRef = baseOb; baseRef.who(); baseRef = dOb1; baseRef.who(); baseRef = dOb2; baseRef.who(); // Вызывает метод who() класса Base. }
public void TestCyclicReferenceWithDifferentTypes() { // this verifies that cyclic reference detection will not // only treat objects of the same type as part of a cycle; // this supports some (broken) equals implementations var original = new Derived1 { reference = new Derived2() }; var cloned = Clone(original); Assert.IsInstanceOf <Derived1>(cloned); Assert.IsInstanceOf <Derived2>(cloned.reference); }
public static void Main() { Derived1 d1 = new Derived1(); Derived2 d2 = new Derived2(); Base b2 = d2; var sb = new StringBuilder(); sb.AppendLine("d1.Method() = " + d1.Method()); sb.AppendLine("d1.Property = " + d1.Property); sb.AppendLine("d2.Method() = " + d2.Method()); sb.AppendLine("d2.Property = " + d2.Property); sb.AppendLine("b2.Method() = " + b2.Method()); sb.AppendLine("b2.Property = " + b2.Property); Console.WriteLine(sb.ToString()); }
static void Main() { int i = 0; Base b; if (i == 0) { b = new Derived1(); } else { b = new Derived2(); } b.SomeVirtualMethod(); }
public void DiscriminatedUnionTwoUsingFirstSecondWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.First<Base, Derived1, Derived2>(d1); Derived2 d2; try { d2 = d.Second; } catch { d2 = null; } Assert.IsNull(d2); }
public void ThrowsOnDuplicateReferencesNotParentsOrRoot() { serializer.EnableAutomaticBackReferences(); var duplicateref = new Derived1(); var original = new Base { BaseChild = duplicateref, BaseChildren = new List <Base> { duplicateref } }; Should.Throw <InvalidOperationException>(() => JObject.FromObject(original, CreateSerializer())); }
public static void Main() { BaseClass baseOb = new BaseClass(); Derived1 dOb1 = new Derived1(); Derived2 dOb2 = new Derived2(); BaseClass baseRef; // a base-class reference baseRef = baseOb; baseRef.who(); baseRef = dOb1; baseRef.who(); baseRef = dOb2; baseRef.who(); }
static void Main(string[] args) { Base obj; //it is just a declaring if (true) { obj = new Derived1(); obj.m = (obj as Derived1).ParticularMethod; } else { obj = new Derived2(); obj.m = (obj as Derived2).ParticularMethod; } Console.WriteLine(obj.m()); //"Particular method of derived 1" Console.ReadKey(); }
static void Main() { Base b; b = new Derived1(); if (b is Derived1) { Console.WriteLine("b = new Derived1();"); } b = new Derived2(); if (b is Derived1) { Console.WriteLine("b = new Derived2"); } }
static void Main() { Base b; Derived1 d; b = new Derived1(); d = b as Derived1; if (d != null) { Console.WriteLine("b = new Derived1();"); } b = new Derived2(); d = b as Derived1; if (d != null) { Console.WriteLine("b = new Derived2();"); } }
static int Main () { Derived1 d1 = new Derived1 (); Derived2 d2 = new Derived2 (); Derived3 d3 = new Derived3 (); Base b1 = d1; Base b2 = d2; Base rb = new Base (); if (d1.Turn () != 4) return 1; if (((IVehicle)d1).Turn () != 4) return 2; if (((Base)d2).Turn () != 8) return 10; if (((IVehicle)d2).Turn () != 7) return 3; if (b2.Turn () != 8) return 4; if (((IVehicle)b2).Turn () != 7) return 5; if (((IVehicle)rb).Stop () != 2) return 6; if (((IVehicle)d1).Stop () != 2) return 7; if (((IVehicle)d2).Stop () != 6) return 8; if (d3.Walk () != 1) return 9; //Console.WriteLine ("TEST {0}", ((IVehicle)b2).Turn ()); return 0; }
public void DoesNotThrowOnDuplicatesOfSpecifiedTypes() { // this will deserialize them as different instances though serializer.EnableAutomaticBackReferences(typeof(Derived1)); var duplicateref = new Derived1(); var original = new Base { BaseChild = duplicateref, BaseChildren = new List <Base> { duplicateref } }; var jObject = JObject.FromObject(original, CreateSerializer()); var copy = jObject.ToObject <Base>(CreateSerializer()); copy.BaseChild.ShouldNotBe(copy.BaseChildren[0]); }
static void Main(string[] args) { Base b = new Derived(); Derived d = new Derived(); Console.WriteLine("#1"); b.DoIt(); Console.WriteLine("#2"); d.DoIt(); b = new Derived1(); d = new Derived1(); Console.WriteLine("#3"); b.DoIt(); Console.WriteLine("#4"); d.DoIt(); Console.WriteLine("#5"); Derived1 e = new Derived1(); e.DoIt(); Console.ReadKey(); }
public void BaseClassTest() { var schema = Schema.Parse(BaseClassSchema); var derived1write = new Derived1() { A = "derived1", B = 7 }; var derived2write = new Derived2() { A = "derived2", C = 3.14 }; // union types (except for [null, type]) need to be manually registered var unionSchema = schema as UnionSchema; var cache = new ClassCache(); cache.LoadClassCache(typeof(Derived1), unionSchema[0]); cache.LoadClassCache(typeof(Derived2), unionSchema[1]); var x = schema as RecordSchema; var writer = new ReflectWriter <BaseClass>(schema, cache); var reader = new ReflectReader <BaseClass>(schema, schema, cache); using (var stream = new MemoryStream(256)) { var encoder = new BinaryEncoder(stream); writer.Write(derived1write, encoder); writer.Write(derived2write, encoder); stream.Seek(0, SeekOrigin.Begin); var decoder = new BinaryDecoder(stream); var derived1read = (Derived1)reader.Read(decoder); var derived2read = (Derived2)reader.Read(decoder); Assert.AreEqual(derived1read.A, derived1write.A); Assert.AreEqual(derived1read.B, derived1write.B); Assert.AreEqual(derived2read.A, derived2write.A); Assert.AreEqual(derived2read.C, derived2write.C); } }
static void Main(string[] args) { // 通常のインスタンス生成 Derived1 dynamicD1 = new Derived1(); Derived2 dynamicD2 = new Derived2(); Base dynamicB = new Base(); // 単純なアップキャスト // 「Base」クラス型の変数に // 「Derived1」クラスのインスタンスを入れる Base staticB1 = new Derived1(); // 「Derived1」クラス型の変数に // 「Base」クラス型の「Derived1」クラスインスタンスを入れるが // ダウンキャストとなるため明示的なキャストが必須 Derived1 staticD1 = (Derived1)staticB1; // 単純なアップキャスト Base staticB2 = new Derived1(); // 「Derived2」クラス型の変数に // 「Base」クラス型の「Derived1」クラスインスタンスを入れる // →「Base」クラス型の変数のためキャストは可能だが // インスタンスとして入っているのは「Derived1」クラスのため実行時にエラーとなる Derived2 staticD2 = (Derived2)staticB2; // 派生クラスに基底クラスのインスタンスは入れられない Derived1 staticD1Error = (Derived1) new Base(); #region パターン_エラー #if ERROR #endif #endregion Console.ReadKey(); }
public static int Main() { Derived1 d1 = new Derived1(); Derived2 d2 = new Derived2(); Base b1 = d1; Base b2 = d2; if (d1.Turn() != 4) { return(1); } if (((IVehicle)d1).Turn() != 4) { return(2); } if (((IVehicle)d2).Turn() != 7) { return(3); } if (b2.Turn() != 8) { return(4); } if (((IVehicle)b2).Turn() != 7) { return(5); } //Console.WriteLine ("TEST {0}", ((IVehicle)b2).Turn ()); return(0); }
public static void Maim() { Derived1 der1 = new Derived1(); Derived2 der2 = new Derived2(); }
public IBase GetObject(int type) { IBase ib = null; switch (type) { case 1: ib = new Derived1(); break; case 2: ib = new Derived2(); break; } return ib; }
public void test13() { var o = new Derived1(); Test13Helper(o); }
public void DiscriminatedUnionTwoUsingFirstSwitchFuncWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.First<Base, Derived1, Derived2>(d1); bool ranFirst = d.Switch(v => true, v => false); Assert.IsTrue(ranFirst); }
public static void Main() { //Test Derived1 Derived1 d1=new Derived1(); check(d1.cbase1y()!=3, "Derived1::cbase1y() failed"); check(d1.cbase2()!=4, "Derived1::cbase2() failed"); //Test Derived2 Derived2 d2=new Derived2(); check(d2.cbase1y()!=6, "Derived2::cbase1y() failed"); check(d2.abase1()!=5, "Derived2::abase1() failed"); //Test Derived3 Derived3 d3=new Derived3(); check(d3.cbase1y()!=7, "Derived3::cbase1y() failed"); check(d3.cbase2()!=8, "Derived3::cbase2() failed"); check(d3.abase1()!=9, "Derived3::abase1() failed"); //Test Bottom1 Bottom1 b1=new Bottom1(); check(b1.cbase1y()!=103, "Bottom1::cbase1y() failed"); check(b1.cbase2()!=104, "Bottom1::cbase2() failed"); //Test Bottom2 Bottom2 b2=new Bottom2(); check(b2.cbase1y()!=206, "Bottom2::cbase1y() failed"); check(b2.abase1()!=205, "Bottom2::abase1() failed"); //Test Bottom3 Bottom3 b3=new Bottom3(); check(b3.cbase1y()!=307, "Bottom3::cbase1y() failed"); check(b3.cbase2()!=308, "Bottom3::cbase2() failed"); check(b3.abase1()!=309, "Bottom3::abase1() failed"); //Test interfaces from c++ classes CBase1 cb1=new CBase1SwigImpl(); CBase2 cb2=new CBase2SwigImpl(); check(cb1.cbase1y()!=1, "CBase1::cbase1y() failed"); check(cb2.cbase2()!=2, "CBase2::cbase2() failed"); //Test abstract class as return value ABase1 ab1=d3.cloneit(); check(ab1.abase1()!=9, "Derived3::abase1() through ABase1 failed"); //Test concrete base class as return value CBase1 cb6=d2.cloneit(); CBase2 cb7=d1.cloneit(); check(cb6.cbase1y()!=6, "Derived2::cbase1y() through CBase1 failed"); check(cb7.cbase2()!=4, "Derived1:cbase2() through ABase1 failed"); //Test multi inheritance CBase1 cb3=new Derived1(); CBase1 cb4=new Derived3(); CBase2 cb5=new Derived3(); ABase1 ab6=new Derived2(); check(cb3.cbase1y()!=3, "Derived1::cbase1y() through CBase1 failed"); check(cb4.cbase1y()!=7, "Derived3::cbase1y() through CBase1 failed"); check(cb5.cbase2()!=8, "Derived3::cbase2() through CBase2 failed"); check(ab6.abase1()!=5, "Derived2::abase1() through ABase1 failed"); //Test base classes as parameter in C# multiple_inheritance_abstract_runme mhar=new multiple_inheritance_abstract_runme(); check(mhar.jcbase1b(d1)!=3, "jcbase1b() through Derived1 as parameter failed"); check(mhar.jcbase1b(d2)!=6, "jcbase1b() through Derived2 as parameter failed"); check(mhar.jcbase1b(d3)!=7, "jcbase1b() through Derived3 as parameter failed"); check(mhar.jcbase2(d1)!=4, "jcbase2() through Derived1 as parameter failed"); check(mhar.jcbase2(d3)!=8, "jcbase2() through Derived3 as parameter failed"); check(mhar.jabase1(d2)!=5, "jabase1() through Derived2 as parameter failed"); check(mhar.jabase1(d3)!=9, "jabase1() through Derived3 as parameter failed"); //Value parameters //Test CBase1 CBase2 as parameters (note slicing for Derived and Bottom classes) check(multiple_inheritance_abstract.InputValCBase1(d1)!=1, "InputValCBase1(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(d2)!=1, "InputValCBase1(), Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(d3)!=1, "InputValCBase1(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase2(d3)!=2, "InputValCBase2(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase2(d1)!=2, "InputValCBase2(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(cb1)!=1, "InputValCBase1(), CBase1 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase2(cb2)!=2, "InputValCBase2(), CBase2 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(b1)!=1, "InputValCBase1(), Bottom1 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(b2)!=1, "InputValCBase1(), Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase1(b3)!=1, "InputValCBase1(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase2(b3)!=2, "InputValCBase2(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputValCBase2(b1)!=2, "InputValCBase2(), Bottom1 as a parameter failed"); //Pointer parameters //Test ABase1 as a parameter check(multiple_inheritance_abstract.InputPtrABase1(d2)!=5, "InputPtrABase1() through Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrABase1(d3)!=9, "InputPtrABase1() through Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrABase1(b2)!=205, "InputPtrABase1() through Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrABase1(b3)!=309, "InputPtrABase1() through Bottom3 as a parameter failed"); //Test CBase1 CBase2 as parameters check(multiple_inheritance_abstract.InputPtrCBase1(d1)!=3, "InputPtrCBase1(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(d2)!=6, "InputPtrCBase1(), Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(d3)!=7, "InputPtrCBase1(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase2(d3)!=8, "InputPtrCBase2(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase2(d1)!=4, "InputPtrCBase2(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(cb1)!=1, "InputPtrCBase1(), CBase1 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase2(cb2)!=2, "InputPtrCBase2(), CBase2 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(b1)!=103, "InputPtrCBase1(), Bottom1 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(b2)!=206, "InputPtrCBase1(), Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase1(b3)!=307, "InputPtrCBase1(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase2(b3)!=308, "InputPtrCBase2(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputPtrCBase2(b1)!=104, "InputPtrCBase2(), Bottom1 as a parameter failed"); //Reference parameters //Test ABase1 as a parameter check(multiple_inheritance_abstract.InputRefABase1(d2)!=5, "InputRefABase1() through Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputRefABase1(d3)!=9, "InputRefABase1() through Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputRefABase1(b2)!=205, "InputRefABase1() through Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputRefABase1(b3)!=309, "InputRefABase1() through Bottom3 as a parameter failed"); //Test CBase1 CBase2 as parameters check(multiple_inheritance_abstract.InputRefCBase1(d1)!=3, "InputRefCBase1(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(d2)!=6, "InputRefCBase1(), Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(d3)!=7, "InputRefCBase1(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase2(d3)!=8, "InputRefCBase2(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase2(d1)!=4, "InputRefCBase2(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(cb1)!=1, "InputRefCBase1(), CBase1 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase2(cb2)!=2, "InputRefCBase2(), CBase2 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(b1)!=103, "InputRefCBase1(), Bottom1 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(b2)!=206, "InputRefCBase1(), Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase1(b3)!=307, "InputRefCBase1(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase2(b3)!=308, "InputRefCBase2(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputRefCBase2(b1)!=104, "InputRefCBase2(), Bottom1 as a parameter failed"); //Const reference pointer parameters //Test ABase1 as a parameter check(multiple_inheritance_abstract.InputCPtrRefABase1(d2)!=5, "InputCPtrRefABase1() through Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefABase1(d3)!=9, "InputCPtrRefABase1() through Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefABase1(b2)!=205, "InputCPtrRefABase1() through Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefABase1(b3)!=309, "InputCPtrRefABase1() through Bottom3 as a parameter failed"); //Test CBase1 CBase2 as parameters check(multiple_inheritance_abstract.InputCPtrRefCBase1(d1)!=3, "InputCPtrRefCBase1(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(d2)!=6, "InputCPtrRefCBase1(), Derived2 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(d3)!=7, "InputCPtrRefCBase1(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase2(d3)!=8, "InputCPtrRefCBase2(), Derived3 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase2(d1)!=4, "InputCPtrRefCBase2(), Derived1 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(cb1)!=1, "InputCPtrRefCBase1(), CBase1 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase2(cb2)!=2, "InputCPtrRefCBase2(), CBase2 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(b1)!=103, "InputCPtrRefCBase1(), Bottom1 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(b2)!=206, "InputCPtrRefCBase1(), Bottom2 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase1(b3)!=307, "InputCPtrRefCBase1(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase2(b3)!=308, "InputCPtrRefCBase2(), Bottom3 as a parameter failed"); check(multiple_inheritance_abstract.InputCPtrRefCBase2(b1)!=104, "InputCPtrRefCBase2(), Bottom1 as a parameter failed"); //Derived classes as parameters check(multiple_inheritance_abstract.InputValDerived1(d1)!=3+4, "InputValDerived1() failed"); check(multiple_inheritance_abstract.InputValDerived2(d2)!=6+5, "InputValDerived2() failed"); check(multiple_inheritance_abstract.InputValDerived3(d3)!=7+8+9, "InputValDerived3() failed"); check(multiple_inheritance_abstract.InputRefDerived1(d1)!=3+4, "InputRefDerived1() failed"); check(multiple_inheritance_abstract.InputRefDerived2(d2)!=6+5, "InputRefDerived2() failed"); check(multiple_inheritance_abstract.InputRefDerived3(d3)!=7+8+9, "InputRefDerived3() failed"); check(multiple_inheritance_abstract.InputPtrDerived1(d1)!=3+4, "InputPtrDerived1() failed"); check(multiple_inheritance_abstract.InputPtrDerived2(d2)!=6+5, "InputPtrDerived2() failed"); check(multiple_inheritance_abstract.InputPtrDerived3(d3)!=7+8+9, "InputPtrDerived3() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived1(d1)!=3+4, "InputCPtrRefDerived1() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived2(d2)!=6+5, "InputCPtrRefDerived2() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived3(d3)!=7+8+9, "InputCPtrRefDerived3() failed"); //Bottom classes as Derived parameters check(multiple_inheritance_abstract.InputValDerived1(b1)!=3+4, "InputValDerived1() failed"); check(multiple_inheritance_abstract.InputValDerived2(b2)!=6+5, "InputValDerived2() failed"); check(multiple_inheritance_abstract.InputValDerived3(b3)!=7+8+9, "InputValDerived3() failed"); check(multiple_inheritance_abstract.InputRefDerived1(b1)!=103+104, "InputRefDerived1() failed"); check(multiple_inheritance_abstract.InputRefDerived2(b2)!=206+205, "InputRefDerived2() failed"); check(multiple_inheritance_abstract.InputRefDerived3(b3)!=307+308+309, "InputRefDerived3() failed"); check(multiple_inheritance_abstract.InputPtrDerived1(b1)!=103+104, "InputPtrDerived1() failed"); check(multiple_inheritance_abstract.InputPtrDerived2(b2)!=206+205, "InputPtrDerived2() failed"); check(multiple_inheritance_abstract.InputPtrDerived3(b3)!=307+308+309, "InputPtrDerived3() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived1(b1)!=103+104, "InputCPtrRefDerived1() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived2(b2)!=206+205, "InputCPtrRefDerived2() failed"); check(multiple_inheritance_abstract.InputCPtrRefDerived3(b3)!=307+308+309, "InputCPtrRefDerived3() failed"); //Bottom classes as Bottom parameters check(multiple_inheritance_abstract.InputValBottom1(b1)!=103+104, "InputValBottom1() failed"); check(multiple_inheritance_abstract.InputValBottom2(b2)!=206+205, "InputValBottom2() failed"); check(multiple_inheritance_abstract.InputValBottom3(b3)!=307+308+309, "InputValBottom3() failed"); check(multiple_inheritance_abstract.InputRefBottom1(b1)!=103+104, "InputRefBottom1() failed"); check(multiple_inheritance_abstract.InputRefBottom2(b2)!=206+205, "InputRefBottom2() failed"); check(multiple_inheritance_abstract.InputRefBottom3(b3)!=307+308+309, "InputRefBottom3() failed"); check(multiple_inheritance_abstract.InputPtrBottom1(b1)!=103+104, "InputPtrBottom1() failed"); check(multiple_inheritance_abstract.InputPtrBottom2(b2)!=206+205, "InputPtrBottom2() failed"); check(multiple_inheritance_abstract.InputPtrBottom3(b3)!=307+308+309, "InputPtrBottom3() failed"); check(multiple_inheritance_abstract.InputCPtrRefBottom1(b1)!=103+104, "InputCPtrRefBottom1() failed"); check(multiple_inheritance_abstract.InputCPtrRefBottom2(b2)!=206+205, "InputCPtrRefBottom2() failed"); check(multiple_inheritance_abstract.InputCPtrRefBottom3(b3)!=307+308+309, "InputCPtrRefBottom3() failed"); // Return pointers check(multiple_inheritance_abstract.MakePtrDerived1_CBase1().cbase1y()!=3, "MakePtrDerived1_CBase1 failed"); check(multiple_inheritance_abstract.MakePtrDerived1_CBase2().cbase2()!=4, "MakePtrDerived1_CBase2 failed"); check(multiple_inheritance_abstract.MakePtrDerived2_CBase1().cbase1y()!=6, "MakePtrDerived2_CBase1 failed"); check(multiple_inheritance_abstract.MakePtrDerived2_ABase1().abase1()!=5, "MakePtrDerived2_ABase1 failed"); check(multiple_inheritance_abstract.MakePtrDerived3_ABase1().abase1()!=9, "MakePtrDerived3_ABase1 failed"); check(multiple_inheritance_abstract.MakePtrDerived3_CBase1().cbase1y()!=7, "MakePtrDerived3_CBase1 failed"); check(multiple_inheritance_abstract.MakePtrDerived3_CBase2().cbase2()!=8, "MakePtrDerived3_CBase2 failed"); // Return references check(multiple_inheritance_abstract.MakeRefDerived1_CBase1().cbase1y()!=3, "MakeRefDerived1_CBase1 failed"); check(multiple_inheritance_abstract.MakeRefDerived1_CBase2().cbase2()!=4, "MakeRefDerived1_CBase2 failed"); check(multiple_inheritance_abstract.MakeRefDerived2_CBase1().cbase1y()!=6, "MakeRefDerived2_CBase1 failed"); check(multiple_inheritance_abstract.MakeRefDerived2_ABase1().abase1()!=5, "MakeRefDerived2_ABase1 failed"); check(multiple_inheritance_abstract.MakeRefDerived3_ABase1().abase1()!=9, "MakeRefDerived3_ABase1 failed"); check(multiple_inheritance_abstract.MakeRefDerived3_CBase1().cbase1y()!=7, "MakeRefDerived3_CBase1 failed"); check(multiple_inheritance_abstract.MakeRefDerived3_CBase2().cbase2()!=8, "MakeRefDerived3_CBase2 failed"); // Return by value (sliced objects) check(multiple_inheritance_abstract.MakeValDerived1_CBase1().cbase1y()!=1, "MakeValDerived1_CBase1 failed"); check(multiple_inheritance_abstract.MakeValDerived1_CBase2().cbase2()!=2, "MakeValDerived1_CBase2 failed"); check(multiple_inheritance_abstract.MakeValDerived2_CBase1().cbase1y()!=1, "MakeValDerived2_CBase1 failed"); check(multiple_inheritance_abstract.MakeValDerived3_CBase1().cbase1y()!=1, "MakeValDerived3_CBase1 failed"); check(multiple_inheritance_abstract.MakeValDerived3_CBase2().cbase2()!=2, "MakeValDerived3_CBase2 failed"); }
public void DoesNotThrowOnDuplicatesOfSpecifiedTypes() { // this will deserialize them as different instances though serializer.EnableAutomaticBackReferences(typeof(Derived1)); var duplicateref = new Derived1(); var original = new Base { BaseChild = duplicateref, BaseChildren = new List<Base> { duplicateref } }; var jObject = JObject.FromObject(original, CreateSerializer()); var copy = jObject.ToObject<Base>(CreateSerializer()); copy.BaseChild.ShouldNotBe(copy.BaseChildren[0]); }
public void test4() { var obj = new Derived1(); AssertEquals("Derived1", 1, Foo(obj)); }
public void DiscriminatedUnionThreeUsingFirstToString() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> d = DiscriminatedUnion.First<Base, Derived1, Derived2, Derived3>(d1); Assert.AreEqual("{First:" + d1 + "}", d.ToString()); }
public void DiscriminatedUnionTwoUsingFirstIsSecondWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.First<Base, Derived1, Derived2>(d1); Assert.IsFalse(d.IsSecond); }
static int Main() { Derived1 d1 = new Derived1 (); Derived2 d2 = new Derived2 (); Base b1 = d1; Base b2 = d2; if (d1.Turn () != 4) return 1; if (((IVehicle)d1).Turn () != 4) return 2; if (((IVehicle)d2).Turn () != 7) return 3; if (b2.Turn () != 8) return 4; if (((IVehicle)b2).Turn () != 7) return 5; return 0; }
public void DiscriminatedUnionThreeUsingFirstFirstWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> d = DiscriminatedUnion.First<Base, Derived1, Derived2, Derived3>(d1); Assert.AreSame(d1, d.First); }
public void DiscriminatedUnionThreeUsingFirstIsThirdWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> d = DiscriminatedUnion.First<Base, Derived1, Derived2, Derived3>(d1); Assert.IsFalse(d.IsThird); }
public static int DoWork(Derived1 obj) { return(1); }
public void DiscriminatedUnionThreeUsingThirdCreateFirstWorks() { IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> d = DiscriminatedUnion.Third<Base, Derived1, Derived2, Derived3>(new Derived3()); Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> dd = d.CreateFirst(d1); Assert.AreNotSame(d, dd); Assert.AreNotSame(d.Value, dd.Value); Assert.AreSame(d1, dd.Value); Assert.IsTrue(dd.IsFirst); }
public void Visit(Derived1 b) /*do something*/ }
public void DiscriminatedUnionTwoUsingFirstValueWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.First<Base, Derived1, Derived2>(d1); Assert.AreSame(d1, d.Value); }
public void ThrowsOnDuplicateReferencesNotParentsOrRoot() { serializer.EnableAutomaticBackReferences(); var duplicateref = new Derived1(); var original = new Base { BaseChild = duplicateref, BaseChildren = new List<Base> { duplicateref } }; Should.Throw<InvalidOperationException>(() => JObject.FromObject(original, CreateSerializer())); }
public static MethodId Handle( Derived1 inst ) { return MethodId.Handler_Derived1; }
public void DiscriminatedUnionThreeUsingFirstThirdWorking() { Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2, Derived3> d = DiscriminatedUnion.First<Base, Derived1, Derived2, Derived3>(d1); Derived3 d3; try { d3 = d.Third; } catch { d3 = null; } Assert.IsNull(d3); }
public void DiscriminatedUnionTwoUsingSecondCreateFirstWorks() { IDiscriminatedUnion<Base, Derived1, Derived2> d = DiscriminatedUnion.Second<Base, Derived1, Derived2>(new Derived2()); Derived1 d1 = new Derived1(); IDiscriminatedUnion<Base, Derived1, Derived2> dd = d.CreateFirst(d1); Assert.AreNotSame(d, dd); Assert.AreNotSame(d.Value, dd.Value); Assert.AreSame(d1, dd.Value); Assert.IsTrue(dd.IsFirst); }