/// <summary> /// Creates an instance by the contents of the given XmlNode. /// </summary> /// <param name="node"></param> protected object GetObject(XmlNode node) { ObjectInfo oi = GetObjectInfo(node); if (TypeInfo.IsArray(oi.Type)) { int c = GetArrayLength(node); return(CreateArrayInstance(oi, c)); } return(CreateInstance(oi)); }
/// <summary> /// Reads the properties of the specified node and sets them an the parent object. /// </summary> /// <param name="parent"></param> /// <param name="node"></param> /// <remarks> /// This is the central method which is called recursivly! /// </remarks> protected object GetProperties(object parent, XmlNode node) { if (parent == null) { return(parent); } // Get the properties XmlNodeList nl = node.SelectNodes(taglib.PROPERTIES_TAG + "/" + taglib.PROPERTY_TAG); // Properties found? if (nl == null || nl.Count == 0) { // No properties found... perhaps a collection? if (TypeInfo.IsCollection(parent.GetType())) { SetCollectionValues((ICollection)parent, node); } else { // Nothing to do here return(parent); } } // Loop the properties found foreach (XmlNode prop in nl) { // Collect the nodes type information about the property to deserialize ObjectInfo oi = GetObjectInfo(prop); // Enough info? if (oi.IsSufficient && !String.IsNullOrEmpty(oi.Name)) { object obj = null; // Create an instance, but note: arrays always need the size for instantiation if (TypeInfo.IsArray(oi.Type)) { int c = GetArrayLength(prop); obj = CreateArrayInstance(oi, c); } else { obj = CreateInstance(oi); } // Process the property's properties (recursive call of this method) if (obj != null) { obj = GetProperties(obj, prop); } // Setting the instance (or null) as the property's value PropertyInfo pi = parent.GetType().GetProperty(oi.Name); if (obj != null && pi != null) { pi.SetValue(parent, obj, null); } } } var identifyible = parent as IEntityClass; if (identifyible != null) { var list = GetIdentifyibleTypeList(identifyible.GetType()); if (!list.ContainsKey(identifyible.Id)) { list.Add(identifyible.Id, identifyible); return(list[identifyible.Id]); } return(list[identifyible.Id]); } return(parent); }