Exemple #1
0
 // Used at serialization
 // Maps any Type to a new xsi:type representation
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     // Resolve the type and return the type name and namespace
     if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
     {
         typeName      = new XmlDictionaryString(XmlDictionary.Empty, type.Name, 0);
         typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, type.Namespace, 0);
     }
     return(true);
 }
 // Used at serialization
 // Maps any Type to a new xsi:type representation
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     knownTypeResolver.TryResolveType(type, declaredType, NextResolver, out typeName, out typeNamespace);
     if (typeName == null || typeNamespace == null)
     {
         typeName      = new XmlDictionaryString(XmlDictionary.Empty, type.Name, 0);
         typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, type.Namespace, 0);
     }
     return(typeName != null && typeNamespace != null);
 }
 public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (!knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace))
     {
         var dictionary = new XmlDictionary();
         typeName      = dictionary.Add(dataContractType.FullName);
         typeNamespace = dictionary.Add(dataContractType.Assembly.FullName);
     }
     return(true);
 }
Exemple #4
0
 public override bool TryResolveType(Type dcType, Type declaredType, DataContractResolver KTResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (!KTResolver.TryResolveType(dcType, declaredType, null, out typeName, out typeNamespace))
     {
         _type         = dcType;
         typeName      = new XmlDictionary().Add(dcType.FullName + "***");
         typeNamespace = new XmlDictionary().Add(dcType.Assembly.FullName + "***");
     }
     return(true);
 }
Exemple #5
0
    public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
    {
        if (declaredType == typeof(T1))
        {
            typeName      = _typeName;        //null;
            typeNamespace = _typeNamespace;   //null
            return(true);
        }

        return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
    }
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            var a = AttributeUtils.GetAttribute <T>(type);

            if (a != null)
            {
                var dictionary = new XmlDictionary();
                typeName      = dictionary.Add(_contractNamePrefix + a.ContractId);
                typeNamespace = dictionary.Add(_contractNamespace);
                return(true);
            }
            return(knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace));
        }
Exemple #7
0
        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (Identity.ContainsKey(dataContractType))
            {
                var dictionary = new XmlDictionary();
                typeName      = dictionary.Add(Identity[dataContractType]);
                typeNamespace = dictionary.Add(dataContractType.FullName);
                return(true);
            }

            // Defer to the known type resolver
            return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
        }
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            //Console.WriteLine("TryResolveType: type = {0}, declaredType = {1}", type, declaredType);

            if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
            {
                typeName      = _typeDictionary.Add(XmlConvert.EncodeName(type.Name));
                typeNamespace = _typeDictionary.Add(Namespace + type.Namespace);
                return(true);
            }

            return(true);
        }
Exemple #9
0
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            Console.WriteLine("TryResolveType: type = {0}, declaredType = {1}", type, declaredType);

            if (type == typeof(OuterObject) || type == typeof(InnerObject) || type == typeof(InnerObject[]))
            {
                typeName      = _typeDictionary.Add(type.Name);
                typeNamespace = _typeDictionary.Add(Namespace + type.Namespace);
                return(true);
            }

            return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
        }
 public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (dataContractType == typeof(PropiedadTexto))
     {
         XmlDictionary dictionary = new XmlDictionary();
         typeName      = dictionary.Add("PropiedadTexto");
         typeNamespace = dictionary.Add("JuegoMesa");
         return(true);
     }
     else
     {
         return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
     }
 }
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (type.Assembly.GetName().Name == DynamicTypeBuilder.AssemblyName)
     {
         XmlDictionary dic = new XmlDictionary();
         typeName      = dic.Add(type.Name);
         typeNamespace = dic.Add(ResolverNamespace);
         return(true);
     }
     else
     {
         return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
     }
 }
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (type == typeof(IMyEntity))  //|| type == typeof(...)
     {
         XmlDictionary dictionary = new XmlDictionary();
         typeName      = dictionary.Add(type.Name);
         typeNamespace = dictionary.Add(MyEntityNamespace);
         return(true);
     }
     else
     {
         return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
     }
 }
Exemple #13
0
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     // not necessary to hardcode some type name of course, you can use some broader condition
     // like if type belongs to another assembly
     if (type.Name == "SecondData")
     {
         XmlDictionary dictionary = new XmlDictionary();
         // use assembly qualified name
         typeName      = dictionary.Add(type.AssemblyQualifiedName);
         typeNamespace = dictionary.Add("http://tempuri.org");     // some namespace, does not really matter in this case
         return(true);
     }
     return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
 }
Exemple #14
0
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (type == typeof(Manager))
     {
         XmlDictionary dic = new XmlDictionary();
         typeName      = dic.Add(this.Name);
         typeNamespace = dic.Add(this.Namespace);
         return(true);
     }
     else
     {
         return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
     }
 }
Exemple #15
0
 /// <summary>Maps any type to a new xsi:type representation.</summary>
 /// <returns> Type: Returns_Booleantrue if mapping succeeded; otherwise, false.</returns>
 /// <param name="typeNamespace">System.Xml.XmlDictionaryStringhttp://msdn.microsoft.com/en-us/library/system.xml.xmldictionarystring.aspx. The xsi:type namespace.</param>
 /// <param name="knownTypeResolver">System.Runtime.Serialization.DataContractResolverhttp://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractresolver.aspx. The known type resolver.</param>
 /// <param name="type">Returns_Type. The type to map.</param>
 /// <param name="declaredType">Returns_Type. The type declared in the data contract.</param>
 /// <param name="typeName">System.Xml.XmlDictionaryStringhttp://msdn.microsoft.com/en-us/library/system.xml.xmldictionarystring.aspx. The xsi:type name.</param>
 public override bool TryResolveType(
     Type type,
     Type declaredType,
     DataContractResolver knownTypeResolver,
     out XmlDictionaryString typeName,
     out XmlDictionaryString typeNamespace)
 {
     typeName      = (XmlDictionaryString)null;
     typeNamespace = (XmlDictionaryString)null;
     if (!knownTypeResolver.TryResolveType(type, declaredType, (DataContractResolver)null, out typeName, out typeNamespace))
     {
         typeName = new XmlDictionaryString(XmlDictionary.Empty, type.Name, 0);
         Type type1 = type;
         if (type.IsArray)
         {
             Type elementType = type.GetElementType();
             if (elementType.IsArray)
             {
                 elementType = type1.GetElementType();
             }
             Type type2 = elementType;
             if ((object)type2 == null)
             {
                 type2 = type;
             }
             type1 = type2;
         }
         string   empty            = string.Empty;
         object[] customAttributes = type1.GetCustomAttributes(typeof(DataContractAttribute), false);
         if (customAttributes != null)
         {
             object[] objArray = customAttributes;
             int      index    = 0;
             if (index < objArray.Length)
             {
                 DataContractAttribute contractAttribute = (DataContractAttribute)objArray[index];
                 if (!string.IsNullOrEmpty(contractAttribute.Namespace))
                 {
                     string str = contractAttribute.Namespace;
                     typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, str, 0);
                 }
             }
         }
         if (typeNamespace == null)
         {
             typeNamespace = new XmlDictionaryString(XmlDictionary.Empty, type.Namespace, 0);
         }
     }
     return(true);
 }
Exemple #16
0
//      These methods are necessary for standard .Net serialisation
//      For JSon we use different means, have a look in SpreadList.cs for its custom Json.NET handler.

        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (TypeIdentity.Instance.ContainsKey(dataContractType))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeName      = dictionary.Add(TypeIdentity.Instance[dataContractType]);
                typeNamespace = dictionary.Add(dataContractType.FullName);
                return(true);                // indicating that this resolver knows how to handle
            }
            else
            {
                // Defer to the known type resolver
                return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
            }
        }
Exemple #17
0
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (m_TypeToNames.ContainsKey(type))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeNamespace = dictionary.Add(m_TypeToNames[type].Item1);
                typeName      = dictionary.Add(m_TypeToNames[type].Item2);

                return(true);
            }
            else
            {
                return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
            }
        }
Exemple #18
0
            public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver,
                                                out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
            {
                var resolved =
                    knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);

                if (!resolved)
                {
                    typeName      = dictionary.Add(type.FullName);
                    typeNamespace = dictionary.Add(type.Assembly.FullName);
                    return(true);
                }

                return(resolved);
            }
        /// <summary>
        /// Override this method to map a data contract type to an xsi:type name and namespace during serialization.
        /// </summary>
        /// <param name="type">The type to map.</param>
        /// <param name="declaredType">The type declared in the data contract.</param>
        /// <param name="knownTypeResolver">The known type resolver.</param>
        /// <param name="typeName">The xsi:type name.</param>
        /// <param name="typeNamespace">The xsi:type namespace.</param>
        /// <returns>
        /// <c>true</c>, if mapping succeeded; otherwise, <c>false</c>.
        /// </returns>
        public override bool TryResolveType(
            Type type,
            Type declaredType,
            DataContractResolver knownTypeResolver,
            out XmlDictionaryString typeName,
            out XmlDictionaryString typeNamespace)
        {
            if (this.typeToNamesMap.ContainsKey(type))
            {
                typeNamespace = this.dictionary.Add(this.typeToNamesMap[type].Item1);
                typeName      = this.dictionary.Add(this.typeToNamesMap[type].Item2);

                return(true);
            }

            return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
        }
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
            {
                var contract = type.GetCustomAttribute <DataContractAttribute>();
                if (contract != null)
                {
                    var dict = new XmlDictionary();
                    typeName      = dict.Add(contract.Name);
                    typeNamespace = dict.Add(contract.Namespace);
                    return(true);
                }

                return(false);
            }

            return(true); //knowntype went well
        }
Exemple #21
0
        public override bool TryResolveType(
            Type type,
            Type declaredType,
            DataContractResolver knownTypeResolver,
            out XmlDictionaryString typeName,
            out XmlDictionaryString typeNamespace)
        {
            if (knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace))
            {
                return(true);
            }

            var dict = new XmlDictionary(2);

            typeName      = dict.Add(type.FullName);
            typeNamespace = dict.Add(String.Concat(nsPrefix, type.Assembly.FullName));
            return(true);
        }
        public override bool TryResolveType(Type type,
                                            Type declaredType,
                                            DataContractResolver knownTypeResolver,
                                            out XmlDictionaryString typeName,
                                            out XmlDictionaryString typeNamespace)
        {
            var fullName = type.FullName;

            if (_typeToAssemblyLookup.ContainsKey(fullName))
            {
                var dictionary = new XmlDictionary();
                typeName      = dictionary.Add(fullName);
                typeNamespace = dictionary.Add(_xmlNamespace);
                return(true);
            }

            return(knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace));
        }
Exemple #23
0
        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace)
        {
            Debug.WriteLine("TryResolveType ", type.Name);
            var retVal = _typeToNames.ContainsKey(type);

            if (retVal)
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeNamespace = dictionary.Add(_typeToNames[type].Item1);
                typeName      = dictionary.Add(_typeToNames[type].Item2);
            }
            else
            {
                retVal = knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace);
            }

            return(retVal);
        }
Exemple #24
0
 public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
 {
     if (!knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace))
     {
         lock (this.dictionaryLock)
         {
             if (!this.typeDictionary.TryLookup(type.FullName, out typeName))
             {
                 typeName = this.typeDictionary.Add(type.FullName);
             }
             string value = string.Format("lb:{0}", type.Assembly.FullName);
             if (!this.namespaceDictionary.TryLookup(value, out typeNamespace))
             {
                 typeNamespace = this.namespaceDictionary.Add(value);
             }
         }
     }
     return(true);
 }
Exemple #25
0
        public override bool TryResolveType(Type dataContractType, Type declaredType,
                                            DataContractResolver knownTypeResolver, out XmlDictionaryString typeName,
                                            out XmlDictionaryString typeNamespace)
        {
            if (!knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace))
            {
                return(false);
            }
            int index;

            if (serializationDictionary.TryGetValue(typeNamespace.Value, out index))
            {
                typeNamespace = dic.Add(index.ToString());
            }
            else
            {
                serializationDictionary.Add(typeNamespace.Value, serializationIndex);
                typeNamespace = dic.Add(serializationIndex++ + "#" + typeNamespace);
            }
            return(true);
        }
        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            XmlDictionary dic = new XmlDictionary();

            if (dataContractType == typeof(EmptyNsContainer))
            {
                typeName      = dic.Add("EmptyNsContainer");
                typeNamespace = dic.Add("MyNamespace");
                return(true);
            }
            else if (dataContractType == typeof(UknownEmptyNSAddress))
            {
                typeName      = dic.Add("AddressFoo");
                typeNamespace = dic.Add("");
                return(true);
            }
            else
            {
                return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
            }
        }
 public override bool TryResolveType(
     Type type,
     Type declaredType,
     DataContractResolver knownTypeResolver,
     out XmlDictionaryString typeName,
     out XmlDictionaryString typeNamespace)
 {
     if (!knownTypeResolver.TryResolveType(
             type, declaredType, null, out typeName, out typeNamespace))
     {
         if (string.IsNullOrEmpty(type.FullName) ||
             string.IsNullOrEmpty(type.Assembly.FullName))
         {
             return(false);
         }
         var xmlDictionary = new XmlDictionary();
         typeName      = xmlDictionary.Add(XmlConvert.EncodeName(type.FullName));
         typeNamespace = xmlDictionary.Add(XmlConvert.EncodeName(type.Assembly.FullName));
     }
     return(true);
 }
Exemple #28
0
        /// <summary>
        /// Maps a data contract type to an xsi:type name and namespace during serialization.
        /// </summary>
        /// <param name="dataContractType">The type to map.</param>
        /// <param name="declaredType">The type declared in the data contract.</param>
        /// <param name="knownTypeResolver">The known type resolver.</param>
        /// <param name="typeName">The xsi:type name.</param>
        /// <param name="typeNamespace">The xsi:type namespace.</param>
        /// <returns>true if mapping succeeded; otherwise, false.</returns>
        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
        {
            if (dataContractType == typeof(ServiceResponse))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeName      = dictionary.Add("ServiceResponse");
                typeNamespace = dictionary.Add(ServiceNamespace);
                return(true);
            }

            if (dataContractType == typeof(ServiceRequest <TAuthenticationToken>))
            {
                XmlDictionary dictionary = new XmlDictionary();
                typeName      = dictionary.Add("ServiceRequest");
                typeNamespace = dictionary.Add(ServiceNamespace);
                return(true);
            }

            bool result = TokenResolver.TryResolveType(dataContractType, declaredType, knownTypeResolver, out typeName, out typeNamespace);

            if (result)
            {
                return(true);
            }

            result = EventDataResolver.TryResolveType(dataContractType, declaredType, knownTypeResolver, out typeName, out typeNamespace);
            if (result)
            {
                return(true);
            }

            result = TryResolveUnResolvedType(dataContractType, declaredType, knownTypeResolver, ref typeName, ref typeNamespace);
            if (result)
            {
                return(true);
            }

            // Defer to the known type resolver
            return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
        }
    public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
    {
        Type result = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null);

        if (result == null)
        {
            foreach (var derivedType in declaredType.DerivedTypes())
            {
                XmlDictionaryString derivedTypeName;
                XmlDictionaryString derivedTypeNamespace;
                // Figure out if this derived type has the same data contract name and namespace as the incoming name & namespace.
                if (knownTypeResolver.TryResolveType(derivedType, derivedType, null, out derivedTypeName, out derivedTypeNamespace))
                {
                    if (derivedTypeName.Value == typeName && derivedTypeNamespace.Value == typeNamespace)
                    {
                        return(derivedType);
                    }
                }
            }
        }
        return(result);
    }
        public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace)
        {
            EntityUtil.CheckArgumentNull(dataContractType, "dataContractType");
            EntityUtil.CheckArgumentNull(declaredType, "declaredType");
            EntityUtil.CheckArgumentNull(knownTypeResolver, "knownTypeResolver");

            Type nonProxyType = ObjectContext.GetObjectType(dataContractType);

            if (nonProxyType != dataContractType)
            {
                // Type was a proxy type, so map the name to the non-proxy name
                XmlQualifiedName qualifiedName = _exporter.GetSchemaTypeName(nonProxyType);
                XmlDictionary    dictionary    = new XmlDictionary(2);
                typeName      = new XmlDictionaryString(dictionary, qualifiedName.Name, 0);
                typeNamespace = new XmlDictionaryString(dictionary, qualifiedName.Namespace, 1);
                return(true);
            }
            else
            {
                // Type was not a proxy type, so do the default
                return(knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace));
            }
        }
    public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace)
    {
        if (!knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace))
        {

            XmlDictionary dictionary = new XmlDictionary();

            typeName = dictionary.Add(dataContractType.FullName);

            typeNamespace = dictionary.Add(dataContractType.Assembly.FullName);

        }

        return true;
    }