• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Serialization.XmlReflectionImporter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Xml.Serialization.XmlReflectionImporter的典型用法代码示例。如果您正苦于以下问题:C# XmlReflectionImporter类的具体用法?C# XmlReflectionImporter怎么用?C# XmlReflectionImporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



XmlReflectionImporter类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlReflectionImporter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Initialize

        private void Initialize(Type type, string rootName, string rootNamespace, XmlSerializer xmlSerializer)
        {
            if (type == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("type");
            }
            _rootType = type;
            _rootName = rootName;
            _rootNamespace = rootNamespace == null ? string.Empty : rootNamespace;
            _serializer = xmlSerializer;

            if (_serializer == null)
            {
                if (_rootName == null)
                    _serializer = new XmlSerializer(type);
                else
                {
                    XmlRootAttribute xmlRoot = new XmlRootAttribute();
                    xmlRoot.ElementName = _rootName;
                    xmlRoot.Namespace = _rootNamespace;
                    _serializer = new XmlSerializer(type, xmlRoot);
                }
            }
            else
                _isSerializerSetExplicit = true;

            //try to get rootName and rootNamespace from type since root name not set explicitly
            if (_rootName == null)
            {
                XmlTypeMapping mapping = new XmlReflectionImporter(null).ImportTypeMapping(_rootType);
                _rootName = mapping.ElementName;
                _rootNamespace = mapping.Namespace;
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:34,代码来源:XmlSerializerObjectSerializer.cs


示例2: GetSerializer

        public OldContract.XmlStrippedSerializer GetSerializer(Type type)
        {
            OldContract.XmlStrippedSerializer strippedSerializer;
            //Hashtable is thread safe for use by multiple reader threads and a single writing thread,
            //so the ContainsKey call is safe here
            if (cache.ContainsKey(type))
            {
                strippedSerializer = cache[type] as OldContract.XmlStrippedSerializer;
            }
            else
            {
				//create the serializer before locking so that other threads are not blocked here
				
				//Needed the element name of the root element, since we strip it out of our value stored in the database.
				XmlReflectionImporter xmlReflectionImporter = new XmlReflectionImporter();
				XmlTypeMapping xmlTypeMapping = xmlReflectionImporter.ImportTypeMapping(type);

				//Create the new serializer                
				strippedSerializer = new OldContract.XmlStrippedSerializer(new XmlSerializer(type), xmlTypeMapping.XsdElementName, type);
                lock (_syncLock)
                {
                    if (cache.ContainsKey(type))
                    {
                        strippedSerializer = cache[type] as OldContract.XmlStrippedSerializer;
                    }
                    else
                    {
                        //Add it to the cache
                        cache.Add(type, strippedSerializer);
                    }
                }
            }
            return strippedSerializer;
        }
开发者ID:rbramwell,项目名称:OrionSDK,代码行数:34,代码来源:XmlStrippedSerializerCache.cs


示例3: CreateSerializer

 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);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:35,代码来源:XmlSerializerFactory.cs


示例4: XmlSerializer

 /// <include file='doc\XmlSerializer.uex' path='docs/doc[@for="XmlSerializer.XmlSerializer"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public XmlSerializer(Type type, XmlAttributeOverrides overrides, Type[] extraTypes, XmlRootAttribute root, string defaultNamespace) {
     XmlReflectionImporter importer = new XmlReflectionImporter(overrides, defaultNamespace);
     for (int i = 0; i < extraTypes.Length; i++)
         importer.IncludeType(extraTypes[i]);
     tempAssembly = GenerateTempAssembly(importer.ImportTypeMapping(type, root));
     this.events.sender = this;
 }
开发者ID:ArildF,项目名称:masters,代码行数:11,代码来源:xmlserializer.cs


示例5: Map

		private XmlTypeMapping Map(Type t, XmlRootAttribute root)
		{
			XmlReflectionImporter ri = new XmlReflectionImporter();
			XmlTypeMapping tm = ri.ImportTypeMapping(t, root);

			return tm;
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:XmlReflectionImporterTests.cs


示例6: GetLiteralTypeMapping

		XmlTypeMapping GetLiteralTypeMapping ()
		{
			XmlRootAttribute root = new XmlRootAttribute("rootroot");
			Type[] types = new Type[] {typeof(UknTestPart), typeof(AnotherTestPart), typeof(DblStringContainer) };
			XmlReflectionImporter ri = new XmlReflectionImporter ();
			foreach (Type t in types) ri.IncludeType (t);
			return ri.ImportTypeMapping (typeof(Test), root);
		}
开发者ID:carrie901,项目名称:mono,代码行数:8,代码来源:ComplexDataStructure.cs


示例7: UnwrappedTypesXmlSerializerManager

 public UnwrappedTypesXmlSerializerManager()
 {
     this.allTypes = new Dictionary<Type, XmlTypeMapping>();
     this.serializersMap = new Dictionary<Type, XmlSerializer>();
     this.operationTypes = new Dictionary<Object, IList<Type>>();
     importer = new XmlReflectionImporter();
     this.thisLock = new Object();
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:8,代码来源:UnwrappedTypesXmlSerializerManager.cs


示例8: Export

		private XmlSchemas Export (Type type, XmlAttributeOverrides overrides, string defaultNamespace)
		{
			XmlReflectionImporter ri = new XmlReflectionImporter (overrides, defaultNamespace);
			XmlSchemas schemas = new XmlSchemas ();
			XmlSchemaExporter sx = new XmlSchemaExporter (schemas);
			XmlTypeMapping tm = ri.ImportTypeMapping (type);
			sx.ExportTypeMapping (tm);
			return schemas;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:9,代码来源:XmlSchemaExporterTests.cs


示例9: GetInitializer

		public override object GetInitializer (LogicalMethodInfo methodInfo)
		{
			LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo (methodInfo.DeclaringType);
			object[] ats = methodInfo.ReturnTypeCustomAttributeProvider.GetCustomAttributes (typeof(XmlRootAttribute), true);
			XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; 
			
			XmlReflectionImporter importer = new XmlReflectionImporter ();
			importer.IncludeTypes (methodInfo.CustomAttributeProvider);
			XmlTypeMapping map = importer.ImportTypeMapping (methodInfo.ReturnType, root, sti.GetWebServiceLiteralNamespace (sti.WebServiceNamespace));
			return new XmlSerializer (map);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:11,代码来源:XmlReturnWriter.cs


示例10: Program

        public Program()
        {
            XmlReflectionImporter _XmlReflectionImporter = new XmlReflectionImporter();
            XmlSchemas _XmlSchemas = new XmlSchemas();
            XmlSchemaExporter _XmlSchemaExporter = new XmlSchemaExporter(_XmlSchemas);

            XmlTypeMapping map = _XmlReflectionImporter.ImportTypeMapping(typeof(Database));
            _XmlSchemaExporter.ExportTypeMapping(map);

            TextWriter _TextWriter = new StreamWriter("asd.xsd");
            _XmlSchemas[0].Write(_TextWriter);
            _TextWriter.Close();
        }
开发者ID:ConnectDeveloper01,项目名称:dorumon,代码行数:13,代码来源:Program.cs


示例11: GetSerializerInternal

        private XmlStrippedSerializer GetSerializerInternal(Type type, string typeName)
        {
            XmlReflectionImporter xmlReflectionImporter = new XmlReflectionImporter();
            XmlTypeMapping xmlTypeMapping = xmlReflectionImporter.ImportTypeMapping(type);

            //Create the new serializer                
            XmlStrippedSerializer strippedSerializer = new XmlStrippedSerializer(new XmlSerializer(type), xmlTypeMapping.XsdElementName, xmlTypeMapping.Namespace, type);

            lock (cache)
            {
                cache[typeName] = strippedSerializer;
            }

            return strippedSerializer;
        }
开发者ID:rbramwell,项目名称:OrionSDK,代码行数:15,代码来源:XmlStrippedSerializerCache.cs


示例12: GetInitializers

		public override object[] GetInitializers (LogicalMethodInfo[] methodInfos)
		{
			XmlReflectionImporter importer = new XmlReflectionImporter ();
			XmlMapping[] sers = new XmlMapping [methodInfos.Length];
			for (int n=0; n<sers.Length; n++)
			{
				LogicalMethodInfo metinfo = methodInfos[n];
				if (metinfo.IsVoid) 
					sers[n] = null;
				else
				{
					LogicalTypeInfo sti = TypeStubManager.GetLogicalTypeInfo (metinfo.DeclaringType);
					object[] ats = methodInfos[n].ReturnTypeCustomAttributeProvider.GetCustomAttributes (typeof(XmlRootAttribute), true);
					XmlRootAttribute root = ats.Length > 0 ? ats[0] as XmlRootAttribute : null; 
					sers[n] = importer.ImportTypeMapping (methodInfos[n].ReturnType, root, sti.GetWebServiceLiteralNamespace (sti.WebServiceNamespace));
				}
			}
			return XmlSerializer.FromMappings (sers);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:19,代码来源:XmlReturnReader.cs


示例13: ExportXmlSerializable_NestedClassMapping

		public void ExportXmlSerializable_NestedClassMapping () {

			XmlSchemas schemas = new XmlSchemas ();

			XmlReflectionMember xmlReflectionMember = new XmlReflectionMember ();
			XmlSchemaExporter xmlSchemaExporter = new XmlSchemaExporter (schemas);
			XmlReflectionImporter xmlReflectionImporter = new XmlReflectionImporter ();

			//Export mapping for DataSet1 class.
			xmlReflectionMember.MemberType = typeof (DataSet1);
			XmlMembersMapping xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping ("DataSet1Response", "ResponseNamespace",
				new XmlReflectionMember [] { xmlReflectionMember }, true);

			xmlSchemaExporter.ExportMembersMapping (xmlMembersMapping);

			//Export mapping for nested of DataSet1 class.
			xmlReflectionMember.MemberType = typeof (DataSet1.DataTable1DataTable);
			xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping ("DataTable1DataTableResponse", "ResponseNamespace",
				new XmlReflectionMember [] { xmlReflectionMember }, true);

			xmlSchemaExporter.ExportMembersMapping (xmlMembersMapping);

		}
开发者ID:Profit0004,项目名称:mono,代码行数:23,代码来源:XmlExportOfTypedDataSetTest.cs


示例14: ImportXmlTypes

 /// <summary>
 /// Imports the XML types.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="mappings">The mappings.</param>
 /// <param name="importedTypes">The imported types.</param>
 /// <param name="importer">The importer.</param>
 private static void ImportXmlTypes(Type type, List<XmlMapping> mappings, List<Type> importedTypes, XmlReflectionImporter importer)
 {
     XmlTypeMapping mapping = null;
     var importer2 = new XmlReflectionImporter();
     try
     {
         mapping = importer2.ImportTypeMapping(type);
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         return;
     }
     if (mapping != null)
     {
         mapping = importer.ImportTypeMapping(type);
         mappings.Add(mapping);
         importedTypes.Add(type);
     }
 }
开发者ID:Keldrim,项目名称:SharpDX,代码行数:30,代码来源:Utilities.cs


示例15: Initialize

 private void Initialize(Type type, string rootName, string rootNamespace, XmlSerializer xmlSerializer)
 {
     if (type == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("type");
     }
     this.rootType = type;
     this.rootName = rootName;
     this.rootNamespace = (rootNamespace == null) ? string.Empty : rootNamespace;
     this.serializer = xmlSerializer;
     if (this.serializer == null)
     {
         if (this.rootName == null)
         {
             this.serializer = new XmlSerializer(type);
         }
         else
         {
             XmlRootAttribute root = new XmlRootAttribute {
                 ElementName = this.rootName,
                 Namespace = this.rootNamespace
             };
             this.serializer = new XmlSerializer(type, root);
         }
     }
     else
     {
         this.isSerializerSetExplicit = true;
     }
     if (this.rootName == null)
     {
         XmlTypeMapping mapping = new XmlReflectionImporter().ImportTypeMapping(this.rootType);
         this.rootName = mapping.ElementName;
         this.rootNamespace = mapping.Namespace;
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:36,代码来源:XmlSerializerObjectSerializer.cs


示例16: TestIncludeType

		[Test] // bug #76049
		public void TestIncludeType ()
		{
			XmlReflectionImporter imp = new XmlReflectionImporter ();
			XmlTypeMapping map = imp.ImportTypeMapping (typeof (object));
			imp.IncludeType (typeof (TestSpace));
			XmlSerializer ser = new XmlSerializer (map);
			ser.Serialize (new StringWriter (), new TestSpace ());
		}
开发者ID:frje,项目名称:SharpLang,代码行数:9,代码来源:XmlSerializerTests.cs


示例17: SGenThisAssembly

        /// <summary>
        /// Generates XmlSerializers assembly for this assembly, allowing faster startup with xml serialization.
        /// </summary>
        public static void SGenThisAssembly()
        {
            var xmlRootTypes = new List<Type>();
            var assembly = typeof(Utilities).Assembly;
            var mappings = new List<XmlMapping>();
            var allXmlTypeToSerialize = new List<Type>();
            var importer = new XmlReflectionImporter();

            foreach (var type in assembly.GetTypes())
            {
                if (type.GetCustomAttributes(typeof(XmlRootAttribute), true).Length > 0)
                {
                    xmlRootTypes.Add(type);
                    ImportXmlTypes(type, mappings, allXmlTypeToSerialize, importer);
                }
            }

            if (allXmlTypeToSerialize.Count == 0)
                return;

            string assemblySerializer = XmlSerializer.GetXmlSerializerAssemblyName(allXmlTypeToSerialize[0], null) + ".dll";
            var assemblySerializerTime = File.GetLastWriteTime(assemblySerializer);

            if (!File.Exists(assemblySerializer) || File.GetLastWriteTime(typeof(Utilities).Assembly.Location) > assemblySerializerTime)
            {
                // Delete previous assembly
                File.Delete(assemblySerializer);

                // Regenerate assembly
                var parameters = new CompilerParameters();
                string codePath = Path.GetDirectoryName(assembly.Location);
                var files = new TempFileCollection(codePath, false);
                parameters.TempFiles = files;
                parameters.GenerateInMemory = false;
                parameters.IncludeDebugInformation = true;
                parameters.GenerateInMemory = false;
                XmlSerializer.GenerateSerializer(allXmlTypeToSerialize.ToArray(), mappings.ToArray(), parameters);
                files.Delete();
            }
            else
            {
                Assembly.LoadFrom(assemblySerializer);
            }
        }
开发者ID:Keldrim,项目名称:SharpDX,代码行数:47,代码来源:Utilities.cs


示例18: ReflectType

		XmlTypeMapping ReflectType (TypeData typeData, string ns)
		{
			if (!encodedFormat)
			{
				if (auxXmlRefImporter == null) auxXmlRefImporter = new XmlReflectionImporter ();
				return auxXmlRefImporter.ImportTypeMapping (typeData, ns);
			}
			else
			{
				if (auxSoapRefImporter == null) auxSoapRefImporter = new SoapReflectionImporter ();
				return auxSoapRefImporter.ImportTypeMapping (typeData, ns);
			}
		}
开发者ID:nestalk,项目名称:mono,代码行数:13,代码来源:XmlSchemaImporter.cs


示例19: BeginNamespace

		protected override void BeginNamespace ()
		{
			xmlImporter = new XmlSchemaImporter (LiteralSchemas, ClassNames);
			soapImporter = new SoapSchemaImporter (EncodedSchemas, ClassNames);
			xmlExporter = new XmlCodeExporter (CodeNamespace, null);
			xmlReflectionImporter = new XmlReflectionImporter ();
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:HttpSimpleProtocolImporter.cs


示例20: ExportCode

		CodeNamespace ExportCode (Type type)
		{
			XmlReflectionImporter imp = new XmlReflectionImporter ();
			XmlTypeMapping map = imp.ImportTypeMapping (type);
			CodeNamespace codeNamespace = new CodeNamespace ();
			XmlCodeExporter exp = new XmlCodeExporter (codeNamespace);
			exp.ExportTypeMapping (map);
			return codeNamespace;
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:9,代码来源:XmlCodeExporterTests.cs



注:本文中的System.Xml.Serialization.XmlReflectionImporter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.XmlReflectionMember类代码示例发布时间:2022-05-26
下一篇:
C# Serialization.XmlMembersMapping类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap