Exemplo n.º 1
0
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        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 !uapaot
            _tempAssembly = s_cache[defaultNamespace, type];
            if (_tempAssembly == null)
            {
                lock (s_cache)
                {
                    _tempAssembly = s_cache[defaultNamespace, type];
                    if (_tempAssembly == null)
                    {
                        {
                            XmlSerializerImplementation contract = null;
                            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 = GenerateTempAssembly(_mapping, type, defaultNamespace);
                            }
                            else
                            {
                                // we found the pre-generated assembly, now make sure that the assembly has the right serializer
                                // try to avoid the reflection step, need to get ElementName, namespace and the Key form the type
                                _mapping      = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
                                _tempAssembly = new TempAssembly(new XmlMapping[] { _mapping }, assembly, contract);
                            }
                        }
                    }
                    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
        }
Exemplo n.º 2
0
        /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        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 !FEATURE_SERIALIZATION_UAPAOT
            _tempAssembly = s_cache[defaultNamespace, type];
            if (_tempAssembly == null)
            {
                lock (s_cache)
                {
                    _tempAssembly = s_cache[defaultNamespace, type];
                    if (_tempAssembly == null)
                    {
                        {
                            XmlSerializerImplementation contract = null;
                            Assembly assembly = TempAssembly.LoadGeneratedAssembly(type, defaultNamespace, out contract);
                            if (assembly == null)
                            {
                                if (Mode == SerializationMode.PreGenOnly)
                                {
                                    AssemblyName name           = type.Assembly.GetName();
                                    var          serializerName = Compiler.GetTempAssemblyName(name, defaultNamespace);
                                    throw new FileLoadException(SR.Format(SR.FailLoadAssemblyUnderPregenMode, serializerName));
                                }

                                // need to reflect and generate new serialization assembly
                                XmlReflectionImporter importer = new XmlReflectionImporter(defaultNamespace);
                                _mapping      = importer.ImportTypeMapping(type, null, defaultNamespace);
                                _tempAssembly = GenerateTempAssembly(_mapping, type, defaultNamespace);
                            }
                            else
                            {
                                // we found the pre-generated assembly, now make sure that the assembly has the right serializer
                                // try to avoid the reflection step, need to get ElementName, namespace and the Key form the type
                                _mapping      = XmlReflectionImporter.GetTopLevelMapping(type, defaultNamespace);
                                _tempAssembly = new TempAssembly(new XmlMapping[] { _mapping }, assembly, contract);
                            }
                        }
                    }
                    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);
            }
#endif
        }
Exemplo n.º 3
0
        public Type GetObjectType()
        {
            var  appDir = Helper.GetDirectory();
            Type t      = Type.GetType(Name, false, true);

            if (t == null && TempAssembly == null)
            {
                if (ProcedureType == ProcedureTypes.Assembly)
                {
                    if (DataName != null && DataName != "")
                    {
                        var file = Path.Combine(appDir, DataName);
                        if (File.Exists(file))
                        {
                            TempAssembly = Assembly.LoadFrom(file); //File.ReadAllBytes(FileDataName)
                                                                    //TempAssembly = Assembly.LoadFile(Path.Combine(Environment.CurrentDirectory,  FileDataName)); // Assembly.Load(File.ReadAllBytes(FileDataName))
                        }
                        var list = Store.Select(DBProcedureDataNameInvoker.Instance, CompareType.Equal, DataName);
                        foreach (DBProcedure proc in list)
                        {
                            proc.TempAssembly = TempAssembly;
                        }
                    }
                }
                else if (ProcedureType == ProcedureTypes.Source)
                {
                    if (Source != null && Source != "")
                    {
                        CompilerResults results;
                        if (string.IsNullOrEmpty(DataName))
                        {
                            Compile(Name, new DBProcedure[] { this }, out results, true);
                        }
                        else
                        {
                            Compile(DataName, Store.SelectByFile(DataName), out results, true);
                        }

                        if (TempAssembly == null)
                        {
                            throw new Exception("Ошибка компиляции " + CompilerError(results));
                        }
                    }
                }
                if (TempAssembly == null)
                {
                    TempAssembly = Assembly.GetEntryAssembly();
                }
            }
            if (t == null && TempAssembly != null)
            {
                t = TempAssembly.GetType(Name, false, true);
            }

            if (t == null)
            {
                foreach (Type tt in TempAssembly.GetTypes())
                {
                    if (tt.Name.Equals(Name, StringComparison.OrdinalIgnoreCase) ||
                        tt.FullName.Equals(Name, StringComparison.OrdinalIgnoreCase))
                    {
                        t = tt;
                        break;
                    }
                }
                if (t == null)
                {
                    throw new Exception("Нет Указанного Класса " + Name + " в сборке " + TempAssembly.FullName);
                }
            }
            return(t);
        }
Exemplo n.º 4
0
 internal void Init(TempAssembly tempAssembly)
 {
 }