Пример #1
0
        protected XPathBehaviorAccessor(Type type, IXmlContext context) : base(type, context)
        {
            includedTypes = new XmlIncludedTypeSet();

            foreach (var includedType in context.GetIncludedTypes(ClrType))
            {
                includedTypes.Add(includedType);
            }
        }
Пример #2
0
        public XmlMetadata(DictionaryAdapterMeta meta, IEnumerable <string> reservedNamespaceUris)
        {
            if (meta == null)
            {
                throw Error.ArgumentNull("meta");
            }
            if (reservedNamespaceUris == null)
            {
                throw Error.ArgumentNull("reservedNamespaceUris");
            }

            source        = meta;
            clrType       = meta.Type;
            context       = new XmlContext(this);
            includedTypes = new XmlIncludedTypeSet();

            this.reservedNamespaceUris
                = reservedNamespaceUris as HashSet <string>
                  ?? new HashSet <string>(reservedNamespaceUris);

            var xmlRoot       = null as XmlRootAttribute;
            var xmlType       = null as XmlTypeAttribute;
            var xmlDefaults   = null as XmlDefaultsAttribute;
            var xmlInclude    = null as XmlIncludeAttribute;
            var xmlNamespace  = null as XmlNamespaceAttribute;
            var reference     = null as ReferenceAttribute;
            var xPath         = null as XPathAttribute;
            var xPathVariable = null as XPathVariableAttribute;
            var xPathFunction = null as XPathFunctionAttribute;

            foreach (var behavior in meta.Behaviors)
            {
                if (TryCast(behavior, ref xmlRoot))
                {
                }
                else if (TryCast(behavior, ref xmlType))
                {
                }
                else if (TryCast(behavior, ref xmlDefaults))
                {
                }
                else if (TryCast(behavior, ref xmlInclude))
                {
                    AddPendingInclude(xmlInclude);
                }
                else if (TryCast(behavior, ref xmlNamespace))
                {
                    context.AddNamespace(xmlNamespace);
                }
                else if (TryCast(behavior, ref reference))
                {
                }
                else if (TryCast(behavior, ref xPath))
                {
                }
                else if (TryCast(behavior, ref xPathVariable))
                {
                    context.AddVariable(xPathVariable);
                }
                else if (TryCast(behavior, ref xPathFunction))
                {
                    context.AddFunction(xPathFunction);
                }
            }

            if (xmlDefaults != null)
            {
                qualified  = xmlDefaults.Qualified;
                isNullable = xmlDefaults.IsNullable;
            }

            if (reference != null)
            {
                isReference = true;
            }

            typeLocalName = XmlConvert.EncodeLocalName
                            (
                (!meta.HasXmlType() ? null : meta.GetXmlType().NonEmpty()) ??
                (xmlType == null    ? null : xmlType.TypeName.NonEmpty()) ??
                GetDefaultTypeLocalName(clrType)
                            );

            rootLocalName = XmlConvert.EncodeLocalName
                            (
                (xmlRoot == null ? null : xmlRoot.ElementName.NonEmpty()) ??
                typeLocalName
                            );

            typeNamespaceUri =
                (
                    (xmlType == null ? null : xmlType.Namespace)
                );

            rootNamespaceUri =
                (
                    (xmlRoot == null ? null : xmlRoot.Namespace)
                );

            childNamespaceUri =
                (
                    typeNamespaceUri ??
                    rootNamespaceUri
                );

            if (xPath != null)
            {
                path = xPath.GetPath;
                path.SetContext(context);
            }
        }