Beispiel #1
0
 /// <summary>
 /// Creates a type from the specified assembly and type names included in the TypeInfo parameter.
 /// <b>In case of failure null will be returned.
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 protected Type CreateType(TypeInfo info)
 {
     return(CreateType(info.AssemblyName, info.TypeName));
 }
Beispiel #2
0
        /// <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 IEntity;

            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);
        }