Exemplo n.º 1
0
        /// <summary>
        /// It creates an objet matching xml element name by invoking default constructor
        /// </summary>
        /// <param name="type"></param>
        /// <param name="xmlElementName"></param>
        /// <returns></returns>
        private object CreateObject(Type type, string xmlElementName)
        {
            object[] attrs = type.GetCustomAttributes(true);

            foreach (object attr in attrs)
            {
                BurnXmlElement burnAttribute = attr as BurnXmlElement;

                if (burnAttribute != null && burnAttribute.Name == xmlElementName)
                {
                    ConstructorInfo[] ci = type.GetConstructors();

                    foreach (ConstructorInfo constructor in ci)
                    {
                        ParameterInfo[] pi = constructor.GetParameters();

                        if (pi.Length == 0)
                        {
                            object ob = constructor.Invoke(null);
                            return(ob);
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get property matching xml attribute name
        /// </summary>
        /// <param name="xmlAttributeName">xml attribute name</param>
        /// <param name="obj">object under which property is searched</param>
        /// <returns>property matching xml attribute name</returns>
        private PropertyInfo GetProperty(string xmlAttributeName, object obj)
        {
            PropertyInfo[] properties = obj.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                object[] attributes = property.GetCustomAttributes(true);

                foreach (object attr in attributes)
                {
                    BurnXmlAttribute burnAttribute = attr as BurnXmlAttribute;

                    if (burnAttribute != null && burnAttribute.Name == xmlAttributeName)
                    {
                        return(property);
                    }
                    else
                    {
                        BurnXmlChildElement burnChildElement = attr as BurnXmlChildElement;
                        if (burnChildElement != null)
                        {
                            Type burnChildElementReturnType = property.GetGetMethod().ReturnType;

                            object[] burnChildElementAttrs = burnChildElementReturnType.GetCustomAttributes(true);

                            foreach (object childAttr in burnChildElementAttrs)
                            {
                                BurnXmlElement burnXmlElementAttr = childAttr as BurnXmlElement;

                                if (burnXmlElementAttr != null && burnXmlElementAttr.Name == xmlAttributeName)
                                {
                                    return(property);
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }