GenerateTempAssembly() static private method

static private GenerateTempAssembly ( XmlMapping xmlMapping ) : TempAssembly
xmlMapping XmlMapping
return TempAssembly
        public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location, Evidence evidence)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);

            for (int i = 0; i < extraTypes.Length; i++)
            {
                importer.IncludeType(extraTypes[i]);
            }
            XmlTypeMapping xmlMapping = importer.ImportTypeMapping(type, root, defaultNamespace);

            return((XmlSerializer)XmlSerializer.GenerateTempAssembly(xmlMapping, type, defaultNamespace, location, evidence).Contract.TypedSerializers[xmlMapping.Key]);
        }
Exemplo n.º 2
0
        /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlSerializer CreateSerializer(Type type, string defaultNamespace)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            TempAssembly   tempAssembly = s_cache[defaultNamespace, type];
            XmlTypeMapping mapping      = null;

            if (tempAssembly == null)
            {
                lock (s_cache)
                {
                    tempAssembly = s_cache[defaultNamespace, type];
                    if (tempAssembly == null)
                    {
                        XmlSerializerImplementation contract;
                        Assembly assembly = TempAssembly.LoadGeneratedAssembly(type, defaultNamespace, out contract);
                        if (assembly == null)
                        {
                            // need to reflect and generate new serialization assembly
                            XmlReflectionImporter importer = new XmlReflectionImporter(defaultNamespace);
                            mapping      = importer.ImportTypeMapping(type, null, defaultNamespace);
                            tempAssembly = XmlSerializer.GenerateTempAssembly(mapping, type, defaultNamespace);
                        }
                        else
                        {
                            tempAssembly = new TempAssembly(contract);
                        }
                        s_cache.Add(defaultNamespace, type, tempAssembly);
                    }
                }
            }
            if (mapping == null)
            {
                mapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
            }
            return((XmlSerializer)tempAssembly.Contract.GetSerializer(type));
        }
Exemplo n.º 3
0
        public XmlSerializer CreateSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace, string location)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (location != null)
            {
                DemandForUserLocationOrEvidence();
            }

            XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);

            for (int i = 0; i < extraTypes.Length; i++)
            {
                importer.IncludeType(extraTypes[i]);
            }
            XmlTypeMapping mapping      = importer.ImportTypeMapping(type, root, defaultNamespace);
            TempAssembly   tempAssembly = XmlSerializer.GenerateTempAssembly(mapping, type, defaultNamespace, location);

            return((XmlSerializer)tempAssembly.Contract.TypedSerializers[mapping.Key]);
        }
        public XmlSerializer CreateSerializer(Type type, string defaultNamespace)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            TempAssembly   assembly   = cache[defaultNamespace, type];
            XmlTypeMapping xmlMapping = null;

            if (assembly == null)
            {
                lock (cache)
                {
                    assembly = cache[defaultNamespace, type];
                    if (assembly == null)
                    {
                        XmlSerializerImplementation implementation;
                        if (TempAssembly.LoadGeneratedAssembly(type, defaultNamespace, out implementation) == null)
                        {
                            xmlMapping = new XmlReflectionImporter(defaultNamespace).ImportTypeMapping(type, null, defaultNamespace);
                            assembly   = XmlSerializer.GenerateTempAssembly(xmlMapping, type, defaultNamespace);
                        }
                        else
                        {
                            assembly = new TempAssembly(implementation);
                        }
                        cache.Add(defaultNamespace, type, assembly);
                    }
                }
            }
            if (xmlMapping == null)
            {
                xmlMapping = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
            }
            return(assembly.Contract.GetSerializer(type));
        }
        /// <include file='doc\XmlSerializerFactory.uex' path='docs/doc[@for="XmlSerializerFactory.CreateSerializer5"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public XmlSerializer CreateSerializer(XmlTypeMapping xmlTypeMapping)
        {
            TempAssembly tempAssembly = XmlSerializer.GenerateTempAssembly(xmlTypeMapping);

            return((XmlSerializer)tempAssembly.Contract.TypedSerializers[xmlTypeMapping.Key]);
        }