/// <summary> /// Purpose of this program is to demonstrate the OO concepts and keywords we have used so far /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Create a gp, parent and child. Follow the contructors Console.WriteLine("Creating a grandparent"); GrandparentA gp = new GrandparentA(); Console.WriteLine($"GP: {gp.PublicDerivedStringA} "); Console.WriteLine(gp.VirtualMethodA2("Foo")); Console.WriteLine("*****************************"); Console.WriteLine("Creating a parent"); ParentB p = new ParentB("Red"); Console.WriteLine($"P: {p.PublicDerivedStringA}"); Console.WriteLine(p.VirtualMethodA2("Bar")); Console.WriteLine("*****************************"); Console.WriteLine("Creating a child"); ChildC c = new ChildC("Brown", 11); Console.WriteLine($"C: {c.PublicDerivedStringA}"); Console.WriteLine(c.VirtualMethodA2("Groovy")); // Get the Derived property on each and display it. // Execute the virtual method on each and diplay the result Console.ReadLine(); }
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!"); } } }
public void SerializeParentWithUnexpectedChildShouldWork() { var obj = new ParentB(); Serializer.Serialize(Stream.Null, obj); }
public void WriteXml(Stream outputStream) { if (null == outputStream) { throw new ArgumentNullException(nameof(outputStream)); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(outputStream, settings)) { writer.WriteStartElement("Profile"); writer.WriteStartElement("Id"); writer.WriteValue(Id.ToString()); writer.WriteEndElement(); if (!string.IsNullOrWhiteSpace(_name)) { writer.WriteStartElement("Name"); writer.WriteValue(_name.Trim()); writer.WriteEndElement(); } writer.WriteStartElement("Generation"); writer.WriteValue(Generation); writer.WriteEndElement(); if (ParentA.HasValue) { writer.WriteStartElement("ParentA"); writer.WriteValue(ParentA.ToString()); writer.WriteEndElement(); } if (ParentB.HasValue) { writer.WriteStartElement("ParentB"); writer.WriteValue(ParentB.ToString()); writer.WriteEndElement(); } writer.WriteStartElement("Records"); for (int i = 0; i < Records.Length; i++) { writer.WriteStartElement("Record"); writer.WriteAttributeString("GameType", EnumUtils.GetExpansionPiecesString((ExpansionPieces)i)); writer.WriteAttributeString("EloRating", Records[i].EloRating.ToString()); writer.WriteAttributeString("Wins", Records[i].Wins.ToString()); writer.WriteAttributeString("Losses", Records[i].Losses.ToString()); writer.WriteAttributeString("Draws", Records[i].Draws.ToString()); writer.WriteAttributeString("AutoTrains", Records[i].AutoTrains.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("Creation"); writer.WriteValue(CreationTimestamp); writer.WriteEndElement(); writer.WriteStartElement("LastUpdated"); writer.WriteValue(LastUpdatedTimestamp); writer.WriteEndElement(); StartMetricWeights.WriteMetricWeightsXml(writer, "StartMetricWeights"); EndMetricWeights.WriteMetricWeightsXml(writer, "EndMetricWeights"); writer.WriteEndElement(); // </Profile> } }
private void _read() { _foo = new Child(m_io, this, m_root); _bar = new ParentB(m_io, this, m_root); }
private void _read() { _childSize = m_io.ReadU1(); _elementA = new ParentA(m_io, this, m_root); _elementB = new ParentB(m_io, this, m_root); }
public void WriteXml(Stream outputStream) { if (null == outputStream) { throw new ArgumentNullException("outputStream"); } XmlWriterSettings settings = new XmlWriterSettings { Indent = true }; using (XmlWriter writer = XmlWriter.Create(outputStream, settings)) { writer.WriteStartElement("Profile"); writer.WriteStartElement("Id"); writer.WriteValue(Id.ToString()); writer.WriteEndElement(); if (!string.IsNullOrWhiteSpace(_name)) { writer.WriteStartElement("Name"); writer.WriteValue(_name.Trim()); writer.WriteEndElement(); } writer.WriteStartElement("Generation"); writer.WriteValue(Generation); writer.WriteEndElement(); if (ParentA.HasValue) { writer.WriteStartElement("ParentA"); writer.WriteValue(ParentA.ToString()); writer.WriteEndElement(); } if (ParentB.HasValue) { writer.WriteStartElement("ParentB"); writer.WriteValue(ParentB.ToString()); writer.WriteEndElement(); } writer.WriteStartElement("EloRating"); writer.WriteValue(EloRating); writer.WriteEndElement(); writer.WriteStartElement("Wins"); writer.WriteValue(Wins); writer.WriteEndElement(); writer.WriteStartElement("Losses"); writer.WriteValue(Losses); writer.WriteEndElement(); writer.WriteStartElement("Draws"); writer.WriteValue(Draws); writer.WriteEndElement(); writer.WriteStartElement("Creation"); writer.WriteValue(CreationTimestamp); writer.WriteEndElement(); writer.WriteStartElement("LastUpdated"); writer.WriteValue(LastUpdatedTimestamp); writer.WriteEndElement(); writer.WriteStartElement("StartMetricWeights"); MetricWeights.IterateOverWeights((bugType, bugTypeWeight) => { string key = MetricWeights.GetKeyName(bugType, bugTypeWeight); double value = StartMetricWeights.Get(bugType, bugTypeWeight); writer.WriteStartElement(key); writer.WriteValue(value); writer.WriteEndElement(); }); writer.WriteEndElement(); // </StartMetricWeights> writer.WriteStartElement("EndMetricWeights"); MetricWeights.IterateOverWeights((bugType, bugTypeWeight) => { string key = MetricWeights.GetKeyName(bugType, bugTypeWeight); double value = EndMetricWeights.Get(bugType, bugTypeWeight); writer.WriteStartElement(key); writer.WriteValue(value); writer.WriteEndElement(); }); writer.WriteEndElement(); // </EndMetricWeights> writer.WriteEndElement(); // </Profile> } }