当前位置: 首页>>代码示例>>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;未经允许,请勿转载。