System.Xml.Serialization.XmlSerializer.XmlSerializer C# (CSharp) Method

XmlSerializer() public method

public XmlSerializer ( Type type, string defaultNamespace ) : System.Reflection
type System.Type
defaultNamespace string
return System.Reflection
        public XmlSerializer(Type type, string defaultNamespace)
        {
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            DefaultNamespace = defaultNamespace;
            rootType = type;

            _mapping = GetKnownMapping(type, defaultNamespace);
            if (_mapping != null)
            {
                _primitiveType = type;
                return;
            }
#if !NET_NATIVE
            _tempAssembly = s_cache[defaultNamespace, type];
            if (_tempAssembly == null)
            {
                lock (s_cache)
                {
                    _tempAssembly = s_cache[defaultNamespace, type];
                    if (_tempAssembly == null)
                    {
                        {
                            // need to reflect and generate new serialization assembly
                            XmlReflectionImporter importer = new XmlReflectionImporter(defaultNamespace);
                            _mapping = importer.ImportTypeMapping(type, null, defaultNamespace);
                            _tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace);
                        }
                    }
                    s_cache.Add(defaultNamespace, type, _tempAssembly);
                }
            }
            if (_mapping == null)
            {
                _mapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
            }
#else
            XmlSerializerImplementation contract = GetXmlSerializerContractFromGeneratedAssembly();

            if (contract != null)
            {
                this.innerSerializer = contract.GetSerializer(type);
            }
            else if (ReflectionMethodEnabled)
            {
                var importer = new XmlReflectionImporter(defaultNamespace);
                _mapping = importer.ImportTypeMapping(type, null, defaultNamespace);

                if (_mapping == null)
                {
                    _mapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
                }
            }
#endif
        }

Same methods

XmlSerializer::XmlSerializer ( ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type, Type extraTypes ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type, XmlAttributeOverrides overrides ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type, XmlAttributeOverrides overrides, Type extraTypes, XmlRootAttribute root, string defaultNamespace ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type, XmlAttributeOverrides overrides, Type extraTypes, XmlRootAttribute root, string defaultNamespace, string location ) : System.Reflection
XmlSerializer::XmlSerializer ( Type type, XmlRootAttribute root ) : System.Reflection
XmlSerializer::XmlSerializer ( XmlTypeMapping xmlTypeMapping ) : System.Reflection