Exemple #1
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));
        }
        private static bool TryGetDefinedPrefix(IXmlNode node, string namespaceUri, out string prefix)
        {
            var definedPrefix = node.LookupPrefix(namespaceUri);

            return(string.IsNullOrEmpty(definedPrefix)
                                ? Try.Failure(out prefix)
                                : Try.Success(out prefix, definedPrefix));
        }
Exemple #3
0
        private bool IsMatch()
        {
            IXmlKnownType knownType;

            return(knownTypes.TryGet(this, out knownType)
                                ? Try.Success(out type, knownType.ClrType)
                                : Try.Failure(out type));
        }
Exemple #4
0
        private bool TryGetCompatibleValue(Entry entry, Type type, ref object value)
        {
            var values = entry.Values;

            if (values == null)
            {
                return(false);
            }

            var dictionaryAdapter = null as IDictionaryAdapter;

            // Try to find in the graph a directly assignable value
            foreach (var item in values)
            {
                if (!item.IsInGraph)
                {
                    continue;
                }

                var candidate = item.Value.Target;
                if (candidate == null)
                {
                    continue;
                }

                if (type.IsAssignableFrom(item.Type))
                {
                    if (null != candidate)
                    {
                        return(Try.Success(out value, candidate));
                    }
                }

                if (dictionaryAdapter == null)
                {
                    dictionaryAdapter = candidate as IDictionaryAdapter;
                }
            }

            // Fall back to coercing a DA found in the graph
            if (dictionaryAdapter != null)
            {
                value = dictionaryAdapter.Coerce(type);
                entry.AddValue(type, value, true);
                return(true);
            }

            return(false);
        }
        public bool TryGet(XmlName xsiType, out IXmlIncludedType includedType)
        {
            if (xsiType == XmlName.Empty || xsiType == this.XsiType)
            {
                return(Try.Success(out includedType, this));
            }

            if (!includedTypes.TryGet(xsiType, out includedType))
            {
                return(false);
            }

            if (!ClrType.IsAssignableFrom(includedType.ClrType))
            {
                return(Try.Failure(out includedType));
            }

            return(true);
        }
Exemple #6
0
 public bool TryGet(Type clrType, out IXmlKnownType knownType)
 {
     return(IsMatch(clrType)
                                 ? Try.Success(out knownType, this)
                                 : Try.Failure(out knownType));
 }
Exemple #7
0
 public bool TryGet(IXmlIdentity xmlName, out IXmlKnownType knownType)
 {
     return(IsMatch(xmlName)
                                 ? Try.Success(out knownType, this)
                                 : Try.Failure(out knownType));
 }
Exemple #8
0
 public bool TryGet(Type clrType, out IXmlIncludedType includedType)
 {
     return(clrType == this.clrType
                         ? Try.Success(out includedType, this)
                         : Try.Failure(out includedType));
 }
Exemple #9
0
 public bool TryGet(XmlName xsiType, out IXmlIncludedType includedType)
 {
     return(xsiType == XmlName.Empty || xsiType == this.XsiType
                         ? Try.Success(out includedType, this)
                         : Try.Failure(out includedType));
 }
 public bool TryGet(Type clrType, out IXmlIncludedType includedType)
 {
     return(clrType == this.ClrType
                         ? Try.Success(out includedType, this)
                         : includedTypes.TryGet(clrType, out includedType));
 }