/// <summary> /// Create <see cref="IDataContainer"/> from <paramref name="value"/> /// </summary> /// <param name="name"></param> /// <param name="value"></param> /// <returns></returns> public static IDataContainer CreateObject(string name, object value) { if (value is null) { return(null); } else if (value is IDataContainerSource ids) { return(ids.ToDataContainer()); } var objContainer = new DataContainerBuilder(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.Data(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 ?? DataContainerBuilder.CreateObject(Name, Value)) { obj.WriteXml(writer); } }