Beispiel #1
0
        public XmlName GetDefaultXsiType(Type clrType)
        {
            if (clrType == this.clrType)
            {
                return(this.XsiType);
            }

            IXmlIncludedType include;

            if (includedTypes.TryGet(clrType, out include))
            {
                return(include.XsiType);
            }

            var kind = XmlTypeSerializer.For(clrType).Kind;

            switch (kind)
            {
            case XmlTypeKind.Complex:
                if (!clrType.GetTypeInfo().IsInterface)
                {
                    goto default;
                }
                return(GetXmlMetadata(clrType).XsiType);

            case XmlTypeKind.Collection:
                var itemClrType = clrType.GetCollectionItemType();
                var itemXsiType = GetDefaultXsiType(itemClrType);
                return(new XmlName("ArrayOf" + itemXsiType.LocalName, null));

            default:
                return(new XmlName(clrType.Name, null));
            }
        }
Beispiel #2
0
        private bool TryGetXmlMetadata(Type clrType, out XmlMetadata metadata)
        {
            var kind = XmlTypeSerializer.For(clrType).Kind;

            return(kind == XmlTypeKind.Complex && clrType.GetTypeInfo().IsInterface
                                ? Try.Success(out metadata, GetXmlMetadata(clrType))
                                : Try.Failure(out metadata));
        }
Beispiel #3
0
        protected XmlAccessor(Type clrType, IXmlContext context)
        {
            if (clrType == null)
            {
                throw Error.ArgumentNull("clrType");
            }
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            clrType         = clrType.NonNullable();
            this.clrType    = clrType;
            this.xsiType    = context.GetDefaultXsiType(clrType);
            this.serializer = XmlTypeSerializer.For(clrType);
            this.context    = context;
        }