/// <summary> /// Creates a <see cref="IPropertyContainer"/> which was the same properties and hierarchy as <paramref name="value"/> /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public static IPropertyContainer CreateObject(string name, object value) { if (value is null) { return(null); } else if (value is IPropertyContainerSource ips) { return(ips.ToPropertyContainer()); } var objContainer = new PropertyContainerBuilder(name); objContainer.SetUnderlyingType(value.GetType()); var props = value.GetType().GetProperties(); foreach (var prop in props) { if (prop.CanWrite == false) { continue; } else if (prop.GetCustomAttribute <DataContainerIgnoreAttribute>() is DataContainerIgnoreAttribute) { continue; } objContainer.Property(prop, value); } return(objContainer.Build()); }
/// <summary> /// Implemementation for <see cref="DataObject.WriteXmlContent(XmlWriter)"/> /// </summary> /// <param name="writer"></param> protected override void WriteXmlContent(XmlWriter writer) { // Write type if this based on an object if (ObjectType != null) { writer.WriteObjectXml(new TypeInfo(ObjectType)); } foreach (var obj in _container ?? PropertyContainerBuilder.CreateObject(Name, Value)) { obj.WriteXml(writer); } }