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


C# XmlReflectionImporter.ImportTypeMapping方法代碼示例

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


在下文中一共展示了XmlReflectionImporter.ImportTypeMapping方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: GenerateSchemas

        /// <summary>
        /// Generate a set of schemas from the given types
        /// </summary>
        /// <param name="types">Array of types to generate schemas from</param>
        /// <returns>An array of schemas</returns>
        public IList<XmlSchema> GenerateSchemas(Type[] types)
        {
            Trace.Assert(types != null);
            if (types.Length == 0) return null;

            #region generate the schema from the type
            XmlReflectionImporter reflectionImporter = new XmlReflectionImporter();

            XmlSchemas schemas = new XmlSchemas();

            XmlSchemaExporter exporter = new XmlSchemaExporter(schemas);

            foreach (Type type in types)
            {
                // we can provide the default namespace as a parameter here
                XmlTypeMapping map = reflectionImporter.ImportTypeMapping(type);

                exporter.ExportTypeMapping(map);
            }
            #endregion

            // compile the schemas to make sure they were generated correctly
            schemas.Compile(null, true);

            ResolveImportedSchemas(schemas, types[0].Name);

            // convert the generated schemas to an array of schemas
            return XmlSchemasToArray(schemas);
        }
開發者ID:nujmail,項目名稱:xsd-to-classes,代碼行數:34,代碼來源:ClassXsdGenerator.cs

示例13: GenerateSchema

        /// <summary>
        /// Generate a set of schemas from the given type.
        /// 
        /// Every serializable .NET class can be represented by a schema. 
        /// If that class inherits from another class, then this method will generate more than one schema.
        /// The number of schemas is determines by .NET's own magic formula for when a new schema is needed
        /// but this is probably determined by the namespace attributes added (in the form of XmlRoot and 
        /// XmlType attribute) to the class.
        /// 
        /// We assume that the first schema in the array of generated schemas contains the schema
        /// of the type we requested.
        /// 
        /// </summary>
        /// <param name="type">A type to generate schemas from</param>
        /// <returns>An array of schemas</returns>
        public IList<XmlSchema> GenerateSchema(Type type)
        {
            Type typeToGenerate = type.IsByRef ? type.GetElementType() : type;

            #region generate the schema from the type
            XmlReflectionImporter reflectionImporter = new XmlReflectionImporter();

            XmlSchemas schemas = new XmlSchemas();

            XmlSchemaExporter exporter = new XmlSchemaExporter(schemas);

            XmlTypeMapping map = reflectionImporter.ImportTypeMapping(typeToGenerate);

            exporter.ExportTypeMapping(map);
            #endregion

            #region compile the schemas to make sure they were generated correctly
            XmlSchemaSet schemaSet = new XmlSchemaSet();
            try
            {
                foreach (XmlSchema schema in schemas)
                    schemaSet.Add(schema);
                // some generated classes contain xs:any elements
                // disabling this check allows us to avoid a compilation error
                schemaSet.CompilationSettings.EnableUpaCheck = false;
                schemaSet.XmlResolver = null; // we don't want to resolve any outside schemas
                schemaSet.ValidationEventHandler += new ValidationEventHandler(schemaSet_ValidationEventHandler);
                schemaSet.Compile();
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }
            #endregion

            #region this is a special case for certain types of generated classes
            // when you use the System.Reflection.Emit namespace to generate a type, 
            // and then try to generate schemas from that type, the schemas don't
            // contain "imports" for types in other namespaces.
            // This code block adds those imports.

            // if the number of schemas generated is greater than 1 (meaning there are 
            // potentially types in other namespaces (and hence other schemas)
            // AND if the first schema generated does not include any other schemas
            // we know we're generating a schema that has the charateristics we're
            // expecting
            if (schemas.Count > 1 && schemas[0].Includes.Count == 0)
            {
                // create a list of schemas to process
                IList<XmlSchema> schemaArray = XmlSchemasToArray(schemas);

                // since the number of schemas is greater than one we know that there 
                // are at least 2 schemas, so we can safely index from 1
                for (int i = 1; i < schemaArray.Count; i++)
                {
                    // create a new schema import, and set the namespace
                    XmlSchemaImport import = new XmlSchemaImport();
                    import.Namespace = schemaArray[i].TargetNamespace;

                    // import it into the first schema
                    schemaArray[0].Includes.Add(import);
                }

                schemaSet.Compile();

            }

            #endregion

            #region "fix" the pointers to the included schemas for the generated schemas
            ResolveImportedSchemas(schemas, XmlConvert.EncodeName(typeToGenerate.Name));
            #endregion

            // convert the generated schemas to an array of schemas
            return XmlSchemasToArray(schemas);
        }
開發者ID:nujmail,項目名稱:xsd-to-classes,代碼行數:92,代碼來源:ClassXsdGenerator.cs

示例14: GenerateSerializerGenerics

		public void GenerateSerializerGenerics ()
		{
			XmlReflectionImporter imp = new XmlReflectionImporter ();
			Type type = typeof (List<int>);
			XmlSerializer.GenerateSerializer (
				new Type [] {type},
				new XmlTypeMapping [] {imp.ImportTypeMapping (type)});
		}
開發者ID:frje,項目名稱:SharpLang,代碼行數:8,代碼來源:XmlSerializerTests.cs

示例15: Generate

		public static void Generate (string configFileName, string outputPath)
		{
			SerializationCodeGeneratorConfiguration cnf = null;
			StreamReader sr = new StreamReader (configFileName);
			try
			{
				XmlReflectionImporter ri = new XmlReflectionImporter ();
				ri.AllowPrivateTypes = true;
				XmlSerializer ser = new XmlSerializer (ri.ImportTypeMapping (typeof (SerializationCodeGeneratorConfiguration)));
				cnf = (SerializationCodeGeneratorConfiguration) ser.Deserialize (sr);
			}
			finally
			{
				sr.Close ();
			}
			
			if (outputPath == null) outputPath = "";
			
			CodeIdentifiers ids = new CodeIdentifiers ();
			if (cnf.Serializers != null)
			{
				foreach (SerializerInfo info in cnf.Serializers)
				{					
					Type type;
					if (info.Assembly != null)
					{
						Assembly asm;
						try {
							asm = Assembly.Load (info.Assembly);
						} catch {
							asm = Assembly.LoadFrom (info.Assembly);
						}
						type = asm.GetType (info.ClassName, true);
					}
					else
						type = Type.GetType (info.ClassName);
					
					if (type == null) throw new InvalidOperationException ("Type " + info.ClassName + " not found");
					
					string file = info.OutFileName;
					if (file == null || file.Length == 0) {
						int i = info.ClassName.LastIndexOf (".");
						if (i != -1) file = info.ClassName.Substring (i+1);
						else file = info.ClassName;
						file = ids.AddUnique (file, type) + "Serializer.cs";
					}
					StreamWriter writer = new StreamWriter (Path.Combine (outputPath, file));
					
					try
					{
						XmlTypeMapping map;
						
						if (info.SerializationFormat == SerializationFormat.Literal) {
							XmlReflectionImporter ri = new XmlReflectionImporter ();
							map = ri.ImportTypeMapping (type);
						}
						else {
							SoapReflectionImporter ri = new SoapReflectionImporter ();
							map = ri.ImportTypeMapping (type);
						}
						
						SerializationCodeGenerator gen = new SerializationCodeGenerator (map, info);
						gen.GenerateSerializers (writer);
					}
					finally
					{
						writer.Close ();
					}
				}
			}
		}
開發者ID:thenextman,項目名稱:mono,代碼行數:71,代碼來源:SerializationCodeGenerator.cs


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