コード例 #1
0
        /// Resolve collection property and node for the current XML node. Exception is thrown if nothing is found.
        protected void ResolveCollectionAndTypeForNode(XmlReader reader, IXsContext context, out PropertyInfo collection, out Type type)
        {
            foreach (PropertyInfo c in GetType().GetProperties())
            {
                foreach (XsElementAttribute e in CustomAttributeHelper.All <XsElementAttribute>(c))
                {
                    if (e.Name.Length == 0 && (string.IsNullOrEmpty(e.CollectionItemElementName) || string.Compare(e.CollectionItemElementName, reader.LocalName, StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        collection = c;
                        type       = e.CollectionItemType;
                        if (context != null && (type == null || type.IsInterface || type.IsAbstract))
                        {
                            type = context.ResolveType(reader);
                        }
                        if (type == null || type.IsInterface || type.IsAbstract)
                        {
                            continue;
                        }
                        return;
                    }
                }
            }

            collection = null;
            type       = null;
            throw new XsException(reader, string.Format("Unknown xml element '{0}'", reader.Name));
        }
コード例 #2
0
ファイル: Code.cs プロジェクト: xsharper/xsharper
        /// <summary>
        /// Read child element of the current node
        /// </summary>
        /// <param name="context">XML context</param>
        /// <param name="reader">XML reader</param>
        /// <param name="setToProperty">Property to which the object must be assigned, or null for automatic resolution</param>
        protected override void ReadChildElement(IXsContext context, XmlReader reader, PropertyInfo setToProperty)
        {
            Type t;

            if (setToProperty != null)
            {
                t = setToProperty.PropertyType;
            }
            else
            {
                t = (context == null)?null:context.ResolveType(reader);
            }
            if (t == null)
            {
                throw new XsException(reader, string.Format("Unknown xml element '{0}'", reader.Name));
            }

            object     newObject = Utils.CreateInstance(t);
            IXsElement xse       = newObject as IXsElement;

            if (xse != null)
            {
                xse.ReadXml(context, reader);
            }
            else
            {
                reader.Skip();
            }

            if (setToProperty != null)
            {
                SetChildObject(reader, newObject, setToProperty, null);
            }
            else
            {
                Add((IScriptAction)newObject);
            }
        }
コード例 #3
0
ファイル: Code.cs プロジェクト: xsharper/xsharper
        /// <summary>
        /// Read child element of the current node
        /// </summary>
        /// <param name="context">XML context</param>
        /// <param name="reader">XML reader</param>
        /// <param name="setToProperty">Property to which the object must be assigned, or null for automatic resolution</param>
        protected override void ReadChildElement(IXsContext context, XmlReader reader, PropertyInfo setToProperty)
        {
            Type t;
            if (setToProperty != null)
                t = setToProperty.PropertyType;
            else
                t = (context==null)?null:context.ResolveType(reader);
            if (t==null)
                throw new XsException(reader, string.Format("Unknown xml element '{0}'", reader.Name));

            object newObject = Utils.CreateInstance(t);
            IXsElement xse = newObject as IXsElement;
            if (xse != null)
                xse.ReadXml(context, reader);
            else
                reader.Skip();

            if (setToProperty != null)
                SetChildObject(reader, newObject, setToProperty, null);
            else
                Add((IScriptAction) newObject);
        }
コード例 #4
0
ファイル: XsXmlElement.cs プロジェクト: xsharper/xsharper
        /// Resolve collection property and node for the current XML node. Exception is thrown if nothing is found.
        protected void ResolveCollectionAndTypeForNode(XmlReader reader, IXsContext context, out PropertyInfo collection, out Type type)
        {
            foreach (PropertyInfo c in GetType().GetProperties())
                foreach (XsElementAttribute e in CustomAttributeHelper.All<XsElementAttribute>(c))
                    if (e.Name.Length==0 && (string.IsNullOrEmpty(e.CollectionItemElementName) || string.Compare(e.CollectionItemElementName,reader.LocalName,StringComparison.OrdinalIgnoreCase)==0))
                    {
                        collection = c;
                        type = e.CollectionItemType;
                        if (context!=null && (type == null || type.IsInterface || type.IsAbstract))
                            type = context.ResolveType(reader);
                        if (type == null || type.IsInterface || type.IsAbstract)
                            continue;
                        return;
                    }

            collection = null;
            type = null;
            throw new XsException(reader, string.Format("Unknown xml element '{0}'", reader.Name));
        }