public static object GetItemObject(Type ListType, List <OBJS.Data.DataValue> DataValues, object[] args = null) { object SubItem = Activator.CreateInstance(ListType, args); try { List <PropertyInfo> ListProp = GetProprites(OBJS.Types.Prop, ListType); foreach (PropertyInfo PropInfo in ListProp) { OBJS.Data.DataValue Item = DataValues.FirstOrDefault(A => A.Name == PropInfo.Name); if (Item == null) { continue; } OBJS.XMLDatabaseRetriveItem XMLDatabaseRetriveItem = (OBJS.XMLDatabaseRetriveItem)PropInfo.GetCustomAttributes(typeof(OBJS.XMLDatabaseRetriveItem), true).FirstOrDefault(); string DataValue = Item.Value; object Value = GetValue(PropInfo.PropertyType, DataValue); PropInfo.SetValue(SubItem, Value, null); XMLDatabaseRetriveItem.Location = Item.Location; } List <PropertyInfo> AttributePop = GetProprites(OBJS.Types.Attribute, ListType); foreach (PropertyInfo PropInfo in AttributePop) { OBJS.XMLDatabaseRetriveItem XMLDatabaseRetriveItem = (OBJS.XMLDatabaseRetriveItem)PropInfo.GetCustomAttributes(typeof(OBJS.XMLDatabaseRetriveItem), true).FirstOrDefault(); OBJS.Data.DataValue Item = DataValues.FirstOrDefault(A => A.Name == XMLDatabaseRetriveItem.NodeName); if (Item == null) { continue; } OBJS.Data.DataValue DataValueItem = Item.Attributes.FirstOrDefault(B => B.Name == XMLDatabaseRetriveItem.AttributeName); if (DataValueItem == null) { continue; } string DataValue = DataValueItem.Value; object Value = GetValue(PropInfo.PropertyType, DataValue); PropInfo.SetValue(SubItem, Value, null); XMLDatabaseRetriveItem.Location = Item.Location; } } catch (Exception e) { e.ToString(); } return(SubItem); }
private static void FillData(OBJS.Data DataSet, Type BaseType, object Item) { List <PropertyInfo> Props = GetProprites(OBJS.Types.Prop, BaseType); List <OBJS.Data.DataValue> DataValues = new List <OBJS.Data.DataValue>(); foreach (PropertyInfo Prop in Props) { object ItemObject = Prop.GetValue(Item, null); string ItemValue = (ItemObject != null) ? ItemObject.ToString() : ""; OBJS.Data.DataValue DataValue = new OBJS.Data.DataValue(); DataValue.Name = Prop.Name; DataValue.Value = ItemValue; DataValues.Add(DataValue); } List <PropertyInfo> AttributePop = GetProprites(OBJS.Types.Attribute, BaseType); foreach (PropertyInfo PropInfo in AttributePop) { OBJS.XMLDatabaseRetriveItem XMLDatabaseRetriveItem = (OBJS.XMLDatabaseRetriveItem)PropInfo.GetCustomAttributes(typeof(OBJS.XMLDatabaseRetriveItem), true).FirstOrDefault(); object ItemObject = PropInfo.GetValue(Item, null); string ItemValue = (ItemObject != null) ? ItemObject.ToString() : ""; OBJS.Data.DataValue DataValue = DataValues.Find(A => A.Name == XMLDatabaseRetriveItem.NodeName); if (DataValue != null) { DataValue.Attributes.Add(new OBJS.Data.DataValue() { Name = XMLDatabaseRetriveItem.AttributeName, Value = ItemValue }); } else { DataValue = new OBJS.Data.DataValue(); DataValue.Name = XMLDatabaseRetriveItem.NodeName; DataValue.Attributes.Add(new OBJS.Data.DataValue() { Name = XMLDatabaseRetriveItem.AttributeName, Value = ItemValue }); DataValues.Add(DataValue); } } DataValues.ForEach(T => { DataSet.AddData(T); }); }
private List <OBJS.Data> HandleLoadData(OBJS.Data DataSet, XmlNode Document, string ParentNode = "//DataStore/", string Location = "//DataStore") { List <OBJS.Data> Data = new List <OBJS.Data>(); int id = 1; string SearchClause = ""; if (DataSet.SearchClause != string.Empty) { SearchClause = "[" + DataSet.SearchClause + "]"; } XmlNodeList nodes = Document.SelectNodes(ParentNode + DataSet.DataSet + "/" + DataSet.DefaultItemName + SearchClause); foreach (XmlNode node in nodes) { OBJS.Data FoundData = new OBJS.Data(); FoundData.DataSet = DataSet.DataSet; FoundData.ID = id; FoundData.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]"; foreach (OBJS.Data.DataValue DataValue in DataSet.GetDataValues()) { string value = string.Empty; XmlNodeList DataNodes = node.SelectNodes(DataValue.Name); foreach (XmlNode DataNode in DataNodes) { OBJS.Data.DataValue DataValues = new OBJS.Data.DataValue(); if (DataNode != null) { value = DataNode.InnerText; foreach (XmlAttribute XmlAttribute in DataNode.Attributes) { OBJS.Data.DataValue Attribute = new OBJS.Data.DataValue(); Attribute.Name = XmlAttribute.Name; Attribute.Value = XmlAttribute.Value; Attribute.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]/" + DataValue.Name; DataValues.Attributes.Add(Attribute); } } DataValues.Value = value; DataValues.Name = DataValue.Name; DataValues.Location = Location + "/" + DataSet.DataSet + "/" + DataSet.DefaultItemName + "[" + id + "]/" + DataValue.Name; FoundData.GetDataValues().Add(DataValues); } } foreach (OBJS.Data DataValue in DataSet.GetNestedData()) { if (DataValue.IsSettingsItem) { OBJS.Data NestedData = HandleLoadSettings(DataValue, node, FoundData.Location + "/", FoundData.Location); FoundData.AddData(NestedData); } else { List <OBJS.Data> NestedData = HandleLoadData(DataValue, node, FoundData.Location + "/", FoundData.Location); FoundData.AddData(NestedData); } } Data.Add(FoundData); id++; } return(Data); }
public void AddData(Data.DataValue DataValue) { this.DataValues.Add(DataValue); }