public static void DoTest() { // Create a list with parents and children List <GrandParent> gList = new List <GrandParent>() { new Parent() { ThisDouble = 1.1, ThisInt = 1 }, new Parent() { ThisDouble = 2.2, ThisInt = 2 }, new ChildA() { ThisDouble = 100.1, ThisInt = 101, ThisString = "first child A" }, new ChildB() { ThisDouble = 200.2, ThisInt = 202 }, }; // Test if can return child lists to parent list holders var query3 = new Parent().GetSpecificList(gList); var query4 = new Parent().GetSpecificList_TraditionalWay(gList); query3 = new ChildA().GetSpecificList(gList); query4 = new ChildA().GetSpecificList_TraditionalWay(gList); query3 = new ChildB().GetSpecificList(gList); query4 = new ChildB().GetSpecificList_TraditionalWay(gList); }
private static void Main(string[] args) { ParentA a = new ChildA(); a.DoSomething(); ParentB b = new ChildB(); b.DoSomething(); }
public Rectangle GetRoom() { if (Room != null) { return(Room); } else { if (ChildA != null && ChildB == null) { return(ChildA.GetRoom()); } else if (ChildA == null && ChildB != null) { return(ChildB.GetRoom()); } else { if (Program.Game.Random.Next(2) == 0) { return(ChildA.GetRoom()); } else { return(ChildB.GetRoom()); } } } }
public static ChildBVM Map(this ChildB model) { return(new ChildBVM() { ParentIdVM = model.ParentId, ParentNameVM = model.ParentName, ChildPropertyBVM = model.ChildPropertyB, }); }
void Start() { // in Start() we instantiate ChildA() and ChildB() and assign them to the BaseClass[]. This is valid because they both derive BaseClass. // B/C BaseClass had the abstract functions MoveForward() and ChildUpdate() they can be called in the Update() in the Manager. children = new BaseClass[2]; children [0] = new ChildA(); children [0].Initialize(ChildMesh, ChildMaterial); children [1] = new ChildB(); children [1].Initialize(ChildMesh, ChildMaterial); }
// Use this for initialization void Start() { children = new BaseClass[2]; children [0] = new ChildA(); children [0].Initialize(ChildMesh, ChildMaterial); children [1] = new ChildB(); ChildB cb = new ChildB(); Debug.Log(cb.MyColor); children [1].Initialize(ChildMesh, ChildMaterial); }
private static void Subclass() { using (var session = NHibernateHelper.OpenSession()) { using (var transaction = session.BeginTransaction()) { var parentA = new ParentA() { Name = "Chris" }; var childA = new ChildA() { Name = "Mary", AnotherProperty = "Likes dogs" }; var parentB = new ParentB() { Name = "Chris" }; var childB = new ChildB() { Name = "Mary", AnotherProperty = "Likes dogs" }; var parentC = new ParentC() { Name = "Chris" }; var childC = new ChildC() { Name = "Mary", AnotherProperty = "Likes dogs" }; session.Save(parentA); session.Save(parentB); session.Save(parentC); session.Save(childA); session.Save(childB); session.Save(childC); transaction.Commit(); Console.WriteLine("Done!"); } } }
static void Main(string[] args) { Base baseObj; ChildA childAObj = new ChildA(); ChildB childBObj = new ChildB(); // TERAZ SIĘ ZACZYNA! baseObj = childAObj; baseObj.Get(); baseObj = childBObj; baseObj.Get(); }
private static void Main(string[] args) { //Child in a Parent container! ParentA a = new ChildA(); a.DoSomething(); ParentB b = new ChildB(); b.DoSomething(); Console.ReadKey(); }
private void GrowAsParent(float feed) { var passRatio = GetPassRatio(); _crossSectionArea += passRatio * feed / Length; feed *= 1 - passRatio; if (!HasEnoughFeedForChildren(feed)) { return; } ChildA?.Grow(feed * _growthModel.NutritionRatio); ChildB?.Grow(feed * (1 - _growthModel.NutritionRatio)); }
public async Task JsonSerializationUser() { var start = new ChildB { BaseNumber = 1, ChildANumber = 2, ChildBNumber = 3 }; var result = (ChildB)start.ToJson().FromJsonString <Base>(); Utils.Log(start.ToJson()); Assert.Equal(start.BaseNumber, result.BaseNumber); Assert.Equal(start.ChildANumber, result.ChildANumber); Assert.Equal(start.ChildBNumber, result.ChildBNumber); Assert.DoesNotContain("Wabbajack.Common.Test.Serialization", start.ToJson()); }
public Spot Insert(char ID, Vec Rect) { if (ChildA != null && ChildB != null) { Spot NewNode; if ((NewNode = ChildA.Insert(ID, Rect)) != null) { return(NewNode); } return(ChildB.Insert(ID, Rect)); } if (Rect.X > Area.W || Rect.Y > Area.H) { return(null); } ChildA = new Spot(); ChildB = new Spot(); int WidthDelta = (int)Area.W - (int)Rect.X; int HeightDelta = (int)Area.H - (int)Rect.Y; if (WidthDelta <= HeightDelta) { ChildA.Area.SetPos(Area.X + (int)Rect.X, Area.Y); ChildA.Area.SetSize(WidthDelta, (int)Rect.Y); ChildB.Area.SetPos(Area.X, Area.Y + (int)Rect.Y); ChildB.Area.SetSize(Area.W, HeightDelta); } else { ChildA.Area.SetPos(Area.X, Area.Y + (int)Rect.Y); ChildA.Area.SetSize((int)Rect.X, HeightDelta); ChildB.Area.SetPos(Area.X + (int)Rect.X, Area.Y); ChildB.Area.SetSize(WidthDelta, Area.H); } Area.SetSize((int)Rect.X, (int)Rect.Y); this.ID = ID; return(this); }
public static void Present() { ChildA objectA = new ChildA(); objectA.name = "Value"; // Pomimo tego, że w klasie ChildA nie // zdeklarowano zmiennej name, // jest ona dziedziczona z klasy Parent objectA.intigerVaraible = 6; ChildB objectB = new ChildB(); objectB.name = "Funny Value"; objectB.stringVariable = "Only my variable"; List <Parent> list = new List <Parent>(); list.Add(objectA); list.Add(objectB); // Dzięki temu, że ChildA oraz ChildB dziedziczą z tej samej klasy // mogą być na nią rzutowane dzięki czemu możliwe jest umieszczenie // obiektów różnych klas w jednej liście // ogarniczeniem jedank jest to, że po rzutowaniu można używać tylko // metod, zmiennych... itp wspólnych -- tzn. należąccych do klasy Parent Console.WriteLine("Nazwy obiektów: "); foreach (Parent item in list) { Console.WriteLine($"{item.GetType().Name} name = {item.name}"); } Console.WriteLine("\nWywołanie metody ParentMethod()\n"); foreach (Parent item in list) { item.ParentMethod(); Console.WriteLine(); } Console.WriteLine("\nWywołanie metody ParentAbstractMethod()\n"); foreach (Parent item in list) { item.ParentAbstractMethod(); Console.WriteLine(); } }
private static void SaveServices(ISession session, ITransaction transaction) { Container c = new Container(); ChildA post = new ChildA { Name = "test" }; c.AddService(post); ChildB b = new ChildB(); b.Value = "10"; c.AddMiscellaneous(b); session.SaveOrUpdate(c); transaction.Commit(); }
protected override Operator DuplicateInternal(Dictionary <Operator, Operator> mapping) => new Sequence(ChildA.Duplicate(mapping), ChildB.Duplicate(mapping));
static void Main() { ChildA.Do(); //42 ChildB.Do(); //12 Console.ReadKey(); }
protected override Operator DuplicateInternal(Dictionary <Operator, Operator> mapping) => new PrioritizedChoice(ChildA.Duplicate(mapping), ChildB.Duplicate(mapping));
public void Dispose() { ChildA?.Dispose(); ChildB?.Dispose(); }
public void RefreshBindings() { ChildA.Notify(nameof(ChildA.Check)); ChildB.Notify(nameof(ChildB.Check)); }