KnownTypeDataContractResolver.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / Serialization / System / Runtime / Serialization / KnownTypeDataContractResolver.cs / 1305376 / KnownTypeDataContractResolver.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.Runtime.Serialization 
{
    using System.Xml; 
 
    sealed class KnownTypeDataContractResolver : DataContractResolver
    { 
        XmlObjectSerializerContext context;

        internal KnownTypeDataContractResolver(XmlObjectSerializerContext context)
        { 
            Fx.Assert(context != null, "KnownTypeDataContractResolver should not be instantiated with a null context");
            this.context = context; 
        } 

        public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) 
        {
            if (type == null)
            {
                typeName = null; 
                typeNamespace = null;
                return false; 
            } 
            if (declaredType != null && declaredType.IsInterface && CollectionDataContract.IsCollectionInterface(declaredType))
            { 
                typeName = null;
                typeNamespace = null;
                return true;
            } 

            DataContract contract = DataContract.GetDataContract(type); 
            if (context.IsKnownType(contract, contract.KnownDataContracts, declaredType)) 
            {
                typeName = contract.Name; 
                typeNamespace = contract.Namespace;
                return true;
            }
            else 
            {
                typeName = null; 
                typeNamespace = null; 
                return false;
            } 
        }

        public override Type ResolveName(string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver)
        { 
            if (typeName == null || typeNamespace == null)
                return null; 
            return context.ResolveNameFromKnownTypes(new XmlQualifiedName(typeName, typeNamespace)); 
        }
 
    }

}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK