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

C# Serialization.XmlMapping类代码示例

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

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



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

示例1: GenerateGetSerializer

 private void GenerateGetSerializer(Hashtable serializers, XmlMapping[] xmlMappings)
 {
     this.writer.Write("public override ");
     this.writer.Write(typeof(XmlSerializer).FullName);
     this.writer.Write(" GetSerializer(");
     this.writer.Write(typeof(Type).FullName);
     this.writer.WriteLine(" type) {");
     this.writer.Indent++;
     for (int i = 0; i < xmlMappings.Length; i++)
     {
         if (xmlMappings[i] is XmlTypeMapping)
         {
             Type type = xmlMappings[i].Accessor.Mapping.TypeDesc.Type;
             if (((type != null) && (type.IsPublic || type.IsNestedPublic)) && ((!DynamicAssemblies.IsTypeDynamic(type) && !type.IsGenericType) && (!type.ContainsGenericParameters || !DynamicAssemblies.IsTypeDynamic(type.GetGenericArguments()))))
             {
                 this.writer.Write("if (type == typeof(");
                 this.writer.Write(CodeIdentifier.GetCSharpName(type));
                 this.writer.Write(")) return new ");
                 this.writer.Write((string) serializers[xmlMappings[i].Key]);
                 this.writer.WriteLine("();");
             }
         }
     }
     this.writer.WriteLine("return null;");
     this.writer.Indent--;
     this.writer.WriteLine("}");
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:XmlSerializationCodeGen.cs


示例2: TempAssembly

 internal TempAssembly(XmlMapping[] xmlMappings, Assembly assembly, XmlSerializerImplementation contract)
 {
     this.assemblies = new Hashtable();
     this.assembly = assembly;
     this.InitAssemblyMethods(xmlMappings);
     this.contract = contract;
     this.pregeneratedAssmbly = true;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:TempAssembly.cs


示例3: IsShallow

 internal static bool IsShallow(XmlMapping[] mappings)
 {
     for (int i = 0; i < mappings.Length; i++)
     {
         if ((mappings[i] == null) || mappings[i].shallow)
         {
             return true;
         }
     }
     return false;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:XmlMapping.cs


示例4: TempAssembly

        internal TempAssembly(XmlMapping[] xmlMappings, Type[] types, string defaultNamespace, string location, Evidence evidence) {
            CompilerParameters parameters = new CompilerParameters();
            parameters.GenerateInMemory = true;
            TempFileCollection tempFiles = new TempFileCollection(location);
            parameters.TempFiles = tempFiles;
            assembly = GenerateAssembly(xmlMappings, types, defaultNamespace, evidence, parameters, null, assemblies);
#if DEBUG
            // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
            if (assembly == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Failed to generate XmlSerializer assembly, but did not throw"));
#endif      
            InitAssemblyMethods(xmlMappings);
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:12,代码来源:compilation.cs


示例5: GenerateElement

 internal string GenerateElement(XmlMapping xmlMapping) {
     if (!xmlMapping.IsWriteable)
         return null;
     if (!xmlMapping.GenerateSerializer)
         throw new ArgumentException(Res.GetString(Res.XmlInternalError), "xmlMapping");
     if (xmlMapping is XmlTypeMapping)
         return GenerateTypeElement((XmlTypeMapping)xmlMapping);
     else if (xmlMapping is XmlMembersMapping)
         return GenerateMembersElement((XmlMembersMapping)xmlMapping);
     else
         throw new ArgumentException(Res.GetString(Res.XmlInternalError), "xmlMapping");
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:12,代码来源:XmlSerializationWriterILGen.cs


示例6: CanRead

 internal bool CanRead(XmlMapping mapping, XmlReader xmlReader)
 {
     if (mapping == null)
     {
         return false;
     }
     if (mapping.Accessor.Any)
     {
         return true;
     }
     TempMethod method = this.methods[mapping.Key];
     return xmlReader.IsStartElement(method.name, method.ns);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:13,代码来源:TempAssembly.cs


示例7: ReflectionXmlSerializationWriter

        public ReflectionXmlSerializationWriter(XmlMapping xmlMapping, XmlWriter xmlWriter, XmlSerializerNamespaces namespaces, string encodingStyle, string id)
        {
            Init(xmlWriter, namespaces, encodingStyle, id, null);

            if (!xmlMapping.IsWriteable || !xmlMapping.GenerateSerializer)
            {
                throw new ArgumentException(SR.Format(SR.XmlInternalError, "xmlMapping"));
            }

            if (xmlMapping is XmlTypeMapping || xmlMapping is XmlMembersMapping)
            {
                _mapping = xmlMapping;
            }
            else
            {
                throw new ArgumentException(SR.Format(SR.XmlInternalError, "xmlMapping"));
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:18,代码来源:ReflectionXmlSerializationWriter.cs


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


示例9: TempAssembly

        internal TempAssembly(XmlMapping[] xmlMappings, Type[] types, string defaultNamespace, string location, Evidence evidence) {
            bool containsSoapMapping = false;
            for (int i = 0; i < xmlMappings.Length; i++) {
                xmlMappings[i].CheckShallow();
                if (xmlMappings[i].IsSoap) {
                    containsSoapMapping = true;
                }
            }

            // We will make best effort to use RefEmit for assembly generation
            bool fallbackToCSharpAssemblyGeneration = false;

            if (!containsSoapMapping && !TempAssembly.UseLegacySerializerGeneration) {
                try {
                    assembly = GenerateRefEmitAssembly(xmlMappings, types, defaultNamespace, evidence);
                }
                // Only catch and handle known failures with RefEmit
                catch (CodeGeneratorConversionException) {
                    fallbackToCSharpAssemblyGeneration = true;
                }
                // Add other known exceptions here...
                //
            }
            else {
                fallbackToCSharpAssemblyGeneration = true;
            }
            
            if (fallbackToCSharpAssemblyGeneration) {
                assembly = GenerateAssembly(xmlMappings, types, defaultNamespace, evidence, XmlSerializerCompilerParameters.Create(location), null, assemblies);
            }

#if DEBUG
            // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
            if (assembly == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorDetails, "Failed to generate XmlSerializer assembly, but did not throw"));
#endif
            InitAssemblyMethods(xmlMappings);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:37,代码来源:Compilation.cs


示例10: GenerateTypedSerializer

        internal string GenerateTypedSerializer(string readMethod, string writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass) {
            string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping.TypeDesc.Name));
            serializerName = classes.AddUnique(serializerName + "Serializer", mapping);

            writer.WriteLine();
            writer.Write("public sealed class ");
            writer.Write(CodeIdentifier.GetCSharpName(serializerName));
            writer.Write(" : ");
            writer.Write(baseSerializer);
            writer.WriteLine(" {");
            writer.Indent++;

            writer.WriteLine();
            writer.Write("public override ");
            writer.Write(typeof(bool).FullName);
            writer.Write(" CanDeserialize(");
            writer.Write(typeof(XmlReader).FullName);
            writer.WriteLine(" xmlReader) {");
            writer.Indent++;

            if (mapping.Accessor.Any) {
                writer.WriteLine("return true;");
            }
            else {
                writer.Write("return xmlReader.IsStartElement(");
                WriteQuotedCSharpString(mapping.Accessor.Name);
                writer.Write(", ");
                WriteQuotedCSharpString(mapping.Accessor.Namespace);
                writer.WriteLine(");");
            }
            writer.Indent--;
            writer.WriteLine("}");

            if (writeMethod != null) {
                writer.WriteLine();
                writer.Write("protected override void Serialize(object objectToSerialize, ");
                writer.Write(typeof(XmlSerializationWriter).FullName);
                writer.WriteLine(" writer) {");
                writer.Indent++;
                writer.Write("((");
                writer.Write(writerClass);
                writer.Write(")writer).");
                writer.Write(writeMethod);
                writer.Write("(");
                if (mapping is XmlMembersMapping) {
                    writer.Write("(object[])");
                }
                writer.WriteLine("objectToSerialize);");
                writer.Indent--;
                writer.WriteLine("}");
            }
            if (readMethod != null) {
                writer.WriteLine();
                writer.Write("protected override object Deserialize(");
                writer.Write(typeof(XmlSerializationReader).FullName);
                writer.WriteLine(" reader) {");
                writer.Indent++;
                writer.Write("return ((");
                writer.Write(readerClass);
                writer.Write(")reader).");
                writer.Write(readMethod);
                writer.WriteLine("();");
                writer.Indent--;
                writer.WriteLine("}");
            }
            writer.Indent--;
            writer.WriteLine("}");

            return serializerName;
        }
开发者ID:uQr,项目名称:referencesource,代码行数:70,代码来源:XmlSerializationGeneratedCode.cs


示例11: GenerateEnd

        internal void GenerateEnd(string[] methods, XmlMapping[] xmlMappings, Type[] types) {
            GenerateReferencedMethods();
            GenerateInitCallbacksMethod();

            foreach (CreateCollectionInfo c in createMethods.Values) {
                WriteCreateCollectionMethod(c);
            }

            Writer.WriteLine();
            foreach (string idName in idNames.Values) {
                Writer.Write("string ");
                Writer.Write(idName);
                Writer.WriteLine(";");
            }                

            Writer.WriteLine();
            Writer.WriteLine("protected override void InitIDs() {");
            Writer.Indent++;
            foreach (string id in idNames.Keys) {
                // 
                string idName = (string)idNames[id];
                Writer.Write(idName);
                Writer.Write(" = Reader.NameTable.Add(");
                WriteQuotedCSharpString(id);
                Writer.WriteLine(");");
            }
            Writer.Indent--;
            Writer.WriteLine("}");

            Writer.Indent--;
            Writer.WriteLine("}");
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:32,代码来源:XmlSerializationReader.cs


示例12: GenerateGetSerializer

        //GenerateGetSerializer(serializers, xmlMappings);
        private void GenerateGetSerializer(Dictionary<string, string> serializers, XmlMapping[] xmlMappings, TypeBuilder serializerContractTypeBuilder)
        {
            ilg = new CodeGenerator(serializerContractTypeBuilder);
            ilg.BeginMethod(
                typeof(XmlSerializer),
                "GetSerializer",
                new Type[] { typeof(Type) },
                new string[] { "type" },
                CodeGenerator.PublicOverrideMethodAttributes);

            for (int i = 0; i < xmlMappings.Length; i++)
            {
                if (xmlMappings[i] is XmlTypeMapping)
                {
                    Type type = xmlMappings[i].Accessor.Mapping.TypeDesc.Type;
                    if (type == null)
                        continue;
                    if (!type.GetTypeInfo().IsPublic && !type.GetTypeInfo().IsNestedPublic)
                        continue;
                    // DDB172141: Wrong generated CS for serializer of List<string> type
                    if (type.GetTypeInfo().IsGenericType || type.GetTypeInfo().ContainsGenericParameters)
                        continue;
                    ilg.Ldarg("type");
                    ilg.Ldc(type);
                    ilg.If(Cmp.EqualTo);
                    {
                        ConstructorInfo ctor = CreatedTypes[(string)serializers[xmlMappings[i].Key]].GetConstructor(
                            CodeGenerator.InstanceBindingFlags,
                            Array.Empty<Type>()
                            );
                        ilg.New(ctor);
                        ilg.Stloc(ilg.ReturnLocal);
                        ilg.Br(ilg.ReturnLabel);
                    }
                    ilg.EndIf();
                }
            }
            ilg.Load(null);
            ilg.Stloc(ilg.ReturnLocal);
            ilg.Br(ilg.ReturnLabel);
            ilg.MarkLabel(ilg.ReturnLabel);
            ilg.Ldloc(ilg.ReturnLocal);
            ilg.EndMethod();
        }
开发者ID:omariom,项目名称:corefx,代码行数:45,代码来源:XmlSerializationILGen.cs


示例13: GeneratePublicMethods

 internal FieldBuilder GeneratePublicMethods(string privateName, string publicName, string[] methods, XmlMapping[] xmlMappings, TypeBuilder serializerContractTypeBuilder)
 {
     FieldBuilder fieldBuilder = GenerateHashtableGetBegin(privateName, publicName, serializerContractTypeBuilder);
     if (methods != null && methods.Length != 0 && xmlMappings != null && xmlMappings.Length == methods.Length)
     {
         MethodInfo Hashtable_set_Item = typeof(Hashtable).GetMethod(
             "set_Item",
             new Type[] { typeof(Object), typeof(Object) }
             );
         for (int i = 0; i < methods.Length; i++)
         {
             if (methods[i] == null)
                 continue;
             ilg.Ldloc(typeof(Hashtable), "_tmp");
             ilg.Ldstr(GetCSharpString(xmlMappings[i].Key));
             ilg.Ldstr(GetCSharpString(methods[i]));
             ilg.Call(Hashtable_set_Item);
         }
     }
     GenerateHashtableGetEnd(fieldBuilder);
     return fieldBuilder;
 }
开发者ID:omariom,项目名称:corefx,代码行数:22,代码来源:XmlSerializationILGen.cs


示例14: SerializationCodeGenerator

		public SerializationCodeGenerator (XmlMapping xmlMap, SerializerInfo config)
		{
			_xmlMaps = new XmlMapping [] {xmlMap};
			_config = config;
		}
开发者ID:thenextman,项目名称:mono,代码行数:5,代码来源:SerializationCodeGenerator.cs


示例15: GetFixupCallbackName

		string GetFixupCallbackName (XmlMapping typeMap)
		{
			if (!_mapsToGenerate.Contains (typeMap)) _mapsToGenerate.Add (typeMap);
			
			if (typeMap is XmlTypeMapping)
				return GetUniqueName ("fc", typeMap, "FixupCallback_" + ((XmlTypeMapping)typeMap).XmlType);
			else
				return GetUniqueName ("fc", typeMap, "FixupCallback__Message");
		}
开发者ID:thenextman,项目名称:mono,代码行数:9,代码来源:SerializationCodeGenerator.cs


示例16: SetTempAssembly

 internal void SetTempAssembly(TempAssembly tempAssembly, XmlMapping mapping)
 {
     _tempAssembly = tempAssembly;
     _mapping = mapping;
     _typedSerializer = true;
 }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:6,代码来源:XmlSerializer.cs


示例17: XmlSerializerMappingKey

 public XmlSerializerMappingKey(XmlMapping mapping)
 {
     this.Mapping = mapping;
 }
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:4,代码来源:XmlSerializer.cs


示例18: GenerateWriteObjectElement

		void GenerateWriteObjectElement (XmlMapping xmlMap, string ob, bool isValueList)
		{
			XmlTypeMapping typeMap = xmlMap as XmlTypeMapping;
			Type xmlMapType = (typeMap != null) ? typeMap.TypeData.Type : typeof(object[]);
			
			ClassMap map = (ClassMap)xmlMap.ObjectMap;
			if (!GenerateWriteHook (HookType.attributes, xmlMapType))
			{
				if (map.NamespaceDeclarations != null) {
					WriteLine ("WriteNamespaceDeclarations ((XmlSerializerNamespaces) " + ob + "[email protected]" + map.NamespaceDeclarations.Name + ");");
					WriteLine ("");
				}
	
				XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;
				if (anyAttrMember != null) 
				{
					if (!GenerateWriteMemberHook (xmlMapType, anyAttrMember))
					{
						string cond = GenerateMemberHasValueCondition (anyAttrMember, ob, isValueList);
						if (cond != null) WriteLineInd ("if (" + cond + ") {");
		
						string tmpVar = GetObTempVar ();
						WriteLine ("ICollection " + tmpVar + " = " + GenerateGetMemberValue (anyAttrMember, ob, isValueList) + ";");
						WriteLineInd ("if (" + tmpVar + " != null) {");
		
						string tmpVar2 = GetObTempVar ();
						WriteLineInd ("foreach (XmlAttribute " + tmpVar2 + " in " + tmpVar + ")");
						WriteLineInd ("if (" + tmpVar2 + ".NamespaceURI != xmlNamespace)");
						WriteLine ("WriteXmlAttribute (" + tmpVar2 + ", " + ob + ");");
						Unindent ();
						Unindent ();
						WriteLineUni ("}");
		
						if (cond != null) WriteLineUni ("}");
						WriteLine ("");
						GenerateEndHook ();
					}
				}
				
				ICollection attributes = map.AttributeMembers;
				if (attributes != null)
				{
					foreach (XmlTypeMapMemberAttribute attr in attributes) 
					{
						if (GenerateWriteMemberHook (xmlMapType, attr)) continue;
					
						string val = GenerateGetMemberValue (attr, ob, isValueList);
						string cond = GenerateMemberHasValueCondition (attr, ob, isValueList);
						
						if (cond != null) WriteLineInd ("if (" + cond + ") {");
						
						string strVal = GenerateGetStringValue (attr.MappedType, attr.TypeData, val, false);
						WriteLine ("WriteAttribute (" + GetLiteral(attr.AttributeName) + ", " + GetLiteral(attr.Namespace) + ", " + strVal + ");");
	
						if (cond != null) WriteLineUni ("}");
						GenerateEndHook ();
					}
					WriteLine ("");
				}
				GenerateEndHook ();
			}
			
			if (!GenerateWriteHook (HookType.elements, xmlMapType))
			{
				ICollection members = map.ElementMembers;
				if (members != null)
				{
					foreach (XmlTypeMapMemberElement member in members)
					{
						if (GenerateWriteMemberHook (xmlMapType, member)) continue;
						
						string cond = GenerateMemberHasValueCondition (member, ob, isValueList);
						if (cond != null) WriteLineInd ("if (" + cond + ") {");
						
						string memberValue = GenerateGetMemberValue (member, ob, isValueList);
						Type memType = member.GetType();
	
						if (memType == typeof(XmlTypeMapMemberList))
						{
							GenerateWriteMemberElement ((XmlTypeMapElementInfo) member.ElementInfo[0], memberValue);
						}
						else if (memType == typeof(XmlTypeMapMemberFlatList))
						{
							WriteLineInd ("if (" + memberValue + " != null) {"); 
							GenerateWriteListContent (ob, member.TypeData, ((XmlTypeMapMemberFlatList)member).ListMap, memberValue, false);
							WriteLineUni ("}");
						}
						else if (memType == typeof(XmlTypeMapMemberAnyElement))
						{
							WriteLineInd ("if (" + memberValue + " != null) {"); 
							GenerateWriteAnyElementContent ((XmlTypeMapMemberAnyElement)member, memberValue);
							WriteLineUni ("}");
						}
						else if (memType == typeof(XmlTypeMapMemberAnyElement))
						{
							WriteLineInd ("if (" + memberValue + " != null) {"); 
							GenerateWriteAnyElementContent ((XmlTypeMapMemberAnyElement)member, memberValue);
							WriteLineUni ("}");
						}
						else if (memType == typeof(XmlTypeMapMemberAnyAttribute))
//.........这里部分代码省略.........
开发者ID:thenextman,项目名称:mono,代码行数:101,代码来源:SerializationCodeGenerator.cs


示例19: RegisterSerializer

		public int RegisterSerializer (XmlMapping map)
		{
			if (mappings == null) mappings = new ArrayList ();
			return mappings.Add (map);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:TypeStubManager.cs


示例20: GenerateTypedSerializer

        internal string GenerateTypedSerializer(string readMethod, string writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass)
        {
            string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping.TypeDesc.Name));
            serializerName = classes.AddUnique(serializerName + "Serializer", mapping);

            TypeBuilder typedSerializerTypeBuilder = CodeGenerator.CreateTypeBuilder(
                _moduleBuilder,
                CodeIdentifier.GetCSharpName(serializerName),
                TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
                CreatedTypes[baseSerializer],
                Array.Empty<Type>()
                );

            ilg = new CodeGenerator(typedSerializerTypeBuilder);
            ilg.BeginMethod(
                typeof(Boolean),
                "CanDeserialize",
                new Type[] { typeof(XmlReader) },
                new string[] { "xmlReader" },
                CodeGenerator.PublicOverrideMethodAttributes
            );

            if (mapping.Accessor.Any)
            {
                ilg.Ldc(true);
                ilg.Stloc(ilg.ReturnLocal);
                ilg.Br(ilg.ReturnLabel);
            }
            else
            {
                MethodInfo XmlReader_IsStartElement = typeof(XmlReader).GetMethod(
                     "IsStartElement",
                     CodeGenerator.InstanceBindingFlags,
                     new Type[] { typeof(String), typeof(String) }
                     );
                ilg.Ldarg(ilg.GetArg("xmlReader"));
                ilg.Ldstr(GetCSharpString(mapping.Accessor.Name));
                ilg.Ldstr(GetCSharpString(mapping.Accessor.Namespace));
                ilg.Call(XmlReader_IsStartElement);
                ilg.Stloc(ilg.ReturnLocal);
                ilg.Br(ilg.ReturnLabel);
            }
            ilg.MarkLabel(ilg.ReturnLabel);
            ilg.Ldloc(ilg.ReturnLocal);
            ilg.EndMethod();

            if (writeMethod != null)
            {
                ilg = new CodeGenerator(typedSerializerTypeBuilder);
                ilg.BeginMethod(
                    typeof(void),
                    "Serialize",
                    new Type[] { typeof(object), typeof(XmlSerializationWriter) },
                    new string[] { "objectToSerialize", "writer" },
                    CodeGenerator.ProtectedOverrideMethodAttributes);
                MethodInfo writerType_writeMethod = CreatedTypes[writerClass].GetMethod(
                    writeMethod,
                    CodeGenerator.InstanceBindingFlags,
                    new Type[] { (mapping is XmlMembersMapping) ? typeof(object[]) : typeof(object) }
                    );
                ilg.Ldarg("writer");
                ilg.Castclass(CreatedTypes[writerClass]);
                ilg.Ldarg("objectToSerialize");
                if (mapping is XmlMembersMapping)
                {
                    ilg.ConvertValue(typeof(object), typeof(object[]));
                }
                ilg.Call(writerType_writeMethod);
                ilg.EndMethod();
            }
            if (readMethod != null)
            {
                ilg = new CodeGenerator(typedSerializerTypeBuilder);
                ilg.BeginMethod(
                    typeof(object),
                    "Deserialize",
                    new Type[] { typeof(XmlSerializationReader) },
                    new string[] { "reader" },
                    CodeGenerator.ProtectedOverrideMethodAttributes);
                MethodInfo readerType_readMethod = CreatedTypes[readerClass].GetMethod(
                    readMethod,
                    CodeGenerator.InstanceBindingFlags,
                    Array.Empty<Type>()
                    );
                ilg.Ldarg("reader");
                ilg.Castclass(CreatedTypes[readerClass]);
                ilg.Call(readerType_readMethod);
                ilg.EndMethod();
            }
            typedSerializerTypeBuilder.DefineDefaultConstructor(CodeGenerator.PublicMethodAttributes);
            Type typedSerializerType = typedSerializerTypeBuilder.CreateTypeInfo().AsType();
            CreatedTypes.Add(typedSerializerType.Name, typedSerializerType);

            return typedSerializerType.Name;
        }
开发者ID:omariom,项目名称:corefx,代码行数:95,代码来源:XmlSerializationILGen.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Serialization.XmlMembersMapping类代码示例发布时间:2022-05-26
下一篇:
C# Serialization.XmlElementAttribute类代码示例发布时间: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