Exemplo n.º 1
0
        protected string GetNodeXMLString(string propName, bool isdata)
        {
            if (propName == null || propName.Length < 1)
            {
                return("");
            }

            object o    = GetValueEx(propName);
            Type   type = o.GetType();

            if (XObjectHelper.IsXObjectType(type))
            {
                XObject item = o as XObject;
                //XObject item = GetValueEx( propName ) as XObject;
                if (item == null)
                {
                    return(XObjectHelper.GetEmptyElement(propName));
                }
                return(item.ToFullString(propName));
            }

            if (XObjectHelper.IsXObjectCollectionType(type))
            {
                XObjectCollection col = o as XObjectCollection;
                //XObjectCollection col = GetValueEx( propName ) as XObjectCollection;
                if (col == null)
                {
                    return(XObjectHelper.GetEmptyElement(propName));
                }
                return(col.ToFullString(propName));
            }

            //return XObjectHelper.GetXMLElement( propName, GetValueEx( propName ), isdata );
            return(XObjectHelper.GetXMLElement(propName, o, isdata));
        }
Exemplo n.º 2
0
        protected bool SetValue(string name, XmlNodeReader reader, ref bool hasAlreadyMoveToNext)
        {
            hasAlreadyMoveToNext = false;
            if (name == null || name.Length < 1)
            {
                return(false);
            }

            try
            {
                PropertyInfo pi   = this.GetType().GetProperty(name);
                Type         type = pi.PropertyType;

                if (XObjectHelper.IsXObjectType(type))
                {
                    object theproperty = this.GetType().InvokeMember(name,
                                                                     /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                     BindingFlags.Instance | BindingFlags.GetProperty,
                                                                     null, this, new object[] {});

                    if (theproperty == null && reader.IsEmptyElement == false)
                    {
                        theproperty = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { theproperty });
                    }

                    if (theproperty != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, theproperty, new object[] { reader, name });

                        return(true);
                    }
                }

                if (XObjectHelper.IsXObjectCollectionType(type))
                {
                    object thecollection = this.GetType().InvokeMember(name,
                                                                       /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                                       BindingFlags.Instance | BindingFlags.GetProperty,
                                                                       null, this, new object[] {});

                    if (thecollection == null && reader.IsEmptyElement == false)
                    {
                        thecollection = type.Assembly.CreateInstance(type.FullName);
                        this.GetType().InvokeMember(name,
                                                    /*BindingFlags.DeclaredOnly |*/ BindingFlags.Public |
                                                    BindingFlags.Instance | BindingFlags.SetProperty,
                                                    null, this, new object[] { thecollection });
                    }

                    if (thecollection != null)
                    {
                        XObjectHelper.XBaseType.InvokeMember("InnerLoad",
                                                             BindingFlags.DeclaredOnly |
                                                             BindingFlags.Public | BindingFlags.NonPublic |
                                                             BindingFlags.Instance | BindingFlags.InvokeMethod,
                                                             null, thecollection, new object[] { reader, name });

                        return(true);
                    }
                }

                if (type == typeof(string))
                {
                    object[] olist = pi.GetCustomAttributes(XObjectHelper.XRawXmlStringAttributeType, false);
                    if (olist != null && olist.Length > 0)
                    {
                        XRawXmlStringAttribute a = olist[0] as XRawXmlStringAttribute;
                        if (a != null && a.EnableRawXmlString)
                        {
                            string rawXmlString = reader.ReadInnerXml();
                            hasAlreadyMoveToNext = true;

                            return(SetValueEx(name, rawXmlString));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("(" + name + ") " + e.ToString());
                XObjectManager.NotifyException(this, e);
                return(false);
            }

            return(SetValueEx(name, reader.ReadString()));
        }