當前位置: 首頁>>代碼示例>>C#>>正文


C# Serialization.XmlReflectionImporter類代碼示例

本文整理匯總了C#中System.Xml.Serialization.XmlReflectionImporter的典型用法代碼示例。如果您正苦於以下問題:C# XmlReflectionImporter類的具體用法?C# XmlReflectionImporter怎麽用?C# XmlReflectionImporter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlReflectionImporter類屬於System.Xml.Serialization命名空間,在下文中一共展示了XmlReflectionImporter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的System.Xml.Serialization.XmlReflectionImporter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。