Catel.Runtime.Serialization.Xml.DataContractSerializerFactory.AddTypeToKnownTypesIfSerializable C# (CSharp) Method

AddTypeToKnownTypesIfSerializable() protected method

Adds the type to the known types if the type is serializable.
protected AddTypeToKnownTypesIfSerializable ( Type typeToAdd, XmlSerializerTypeInfo serializerTypeInfo ) : bool
typeToAdd System.Type The type to add.
serializerTypeInfo XmlSerializerTypeInfo The serializer type info.
return bool
        protected virtual bool AddTypeToKnownTypesIfSerializable(Type typeToAdd, XmlSerializerTypeInfo serializerTypeInfo)
        {
            // Collection first, this collection of types is smaller so if we have a hit, we exit sooner
            if (serializerTypeInfo.IsCollectionAlreadyHandled(typeToAdd))
            {
                return true;
            }

            if (serializerTypeInfo.ContainsKnownType(typeToAdd))
            {
                return true;
            }

            serializerTypeInfo.AddCollectionAsHandled(typeToAdd);

            // If this is a special collection type (generic), then we need to make sure that if the inner type is
            // an interface, we do not add it again if already added.
            // See this issue http://catel.codeplex.com/workitem/7167
            if (serializerTypeInfo.IsSpecialCollectionType(typeToAdd))
            {
                // Always ignore
                return false;
            }

            return serializerTypeInfo.AddKnownType(typeToAdd);
        }