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

C# Serialization.MemberMapping类代码示例

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

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



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

示例1: Member

            internal Member(XmlSerializationReaderILGen outerClass, string source, string arraySource, string arrayName, int i, MemberMapping mapping, bool multiRef, string choiceSource) {
                this.source = source;
                this.arrayName = arrayName + "_" + i.ToString(CultureInfo.InvariantCulture);
                this.choiceArrayName = "choice_" + this.arrayName;
                this.choiceSource = choiceSource;

                if (mapping.TypeDesc.IsArrayLike) {
                    if (arraySource != null)
                        this.arraySource = arraySource;
                    else
                        this.arraySource = outerClass.GetArraySource(mapping.TypeDesc, this.arrayName, multiRef);
                    isArray = mapping.TypeDesc.IsArray;
                    isList = !isArray;
                    if (mapping.ChoiceIdentifier != null) {
                        this.choiceArraySource = outerClass.GetArraySource(mapping.TypeDesc, this.choiceArrayName, multiRef);

                        string a = choiceArrayName;
                        string c = "c" + a;
                        string choiceTypeFullName = mapping.ChoiceIdentifier.Mapping.TypeDesc.CSharpName;
                        string castString = "(" + choiceTypeFullName + "[])";

                        string init = a + " = " + castString +
                            "EnsureArrayIndex(" + a + ", " + c + ", " + outerClass.RaCodeGen.GetStringForTypeof(choiceTypeFullName) + ");";
                        this.choiceArraySource = init + outerClass.RaCodeGen.GetStringForArrayMember(a, c + "++", mapping.ChoiceIdentifier.Mapping.TypeDesc);
                    }
                    else {
                        this.choiceArraySource = this.choiceSource;
                    }
                }
                else {
                    this.arraySource = arraySource == null ? source : arraySource;
                    this.choiceArraySource = this.choiceSource;
                }
                this.mapping = mapping;
            }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:35,代码来源:XmlSerializationReaderILGen.cs


示例2: FindDeclaringMapping

 internal MemberMapping FindDeclaringMapping(MemberMapping member, out StructMapping declaringMapping, string parent)
 {
     declaringMapping = null;
     if (this.BaseMapping != null)
     {
         MemberMapping mapping = this.BaseMapping.FindDeclaringMapping(member, out declaringMapping, parent);
         if (mapping != null)
         {
             return mapping;
         }
     }
     if (this.members != null)
     {
         for (int i = 0; i < this.members.Length; i++)
         {
             if (this.members[i].Name == member.Name)
             {
                 if (this.members[i].TypeDesc != member.TypeDesc)
                 {
                     throw new InvalidOperationException(Res.GetString("XmlHiddenMember", new object[] { parent, member.Name, member.TypeDesc.FullName, base.TypeName, this.members[i].Name, this.members[i].TypeDesc.FullName }));
                 }
                 if (!this.members[i].Match(member))
                 {
                     throw new InvalidOperationException(Res.GetString("XmlInvalidXmlOverride", new object[] { parent, member.Name, base.TypeName, this.members[i].Name }));
                 }
                 declaringMapping = this;
                 return this.members[i];
             }
         }
     }
     return null;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:StructMapping.cs


示例3: FindXmlnsIndex

 private int FindXmlnsIndex(MemberMapping[] members)
 {
     for (int i = 0; i < members.Length; i++)
     {
         if (members[i].Xmlns != null)
         {
             return i;
         }
     }
     return -1;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:XmlSerializationWriterCodeGen.cs


示例4: AddUniqueAccessor

 private static void AddUniqueAccessor(MemberMapping member, INameScope elements, INameScope attributes, bool isSequence)
 {
     if (member.Attribute != null)
     {
         AddUniqueAccessor(attributes, member.Attribute);
     }
     else if ((!isSequence && (member.Elements != null)) && (member.Elements.Length > 0))
     {
         for (int i = 0; i < member.Elements.Length; i++)
         {
             AddUniqueAccessor(elements, member.Elements[i]);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:XmlReflectionImporter.cs


示例5: AddMemberMetadata

 private void AddMemberMetadata(CodeAttributeDeclarationCollection metadata, MemberMapping member, bool forceUseMemberName)
 {
     if (member.Elements.Length != 0)
     {
         ElementAccessor accessor = member.Elements[0];
         TypeMapping mapping = accessor.Mapping;
         string str = Accessor.UnescapeName(accessor.Name);
         bool flag = (str == member.Name) && !forceUseMemberName;
         if ((!flag || mapping.TypeDesc.IsAmbiguousDataType) || accessor.IsNullable)
         {
             this.AddElementMetadata(metadata, flag ? null : str, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc : null, accessor.IsNullable);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:SoapCodeExporter.cs


示例6: ImportAccessorMapping

        void ImportAccessorMapping(MemberMapping accessor, FieldModel model, SoapAttributes a, string ns, XmlSchemaForm form) {
            Type accessorType = model.FieldType;
            string accessorName = model.Name;
            accessor.TypeDesc = typeScope.GetTypeDesc(accessorType);
            if (accessor.TypeDesc.IsVoid) {
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidVoid));
            }

            SoapAttributeFlags flags = a.SoapFlags;
            if ((flags & SoapAttributeFlags.Attribute) == SoapAttributeFlags.Attribute) {
                if (!accessor.TypeDesc.IsPrimitive && !accessor.TypeDesc.IsEnum)
                    throw new InvalidOperationException(Res.GetString(Res.XmlIllegalSoapAttribute, accessorName, accessor.TypeDesc.FullName));

                if ((flags & SoapAttributeFlags.Attribute) != flags)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));
                
                AttributeAccessor attribute = new AttributeAccessor();
                attribute.Name = Accessor.EscapeQName(a.SoapAttribute == null || a.SoapAttribute.AttributeName.Length == 0 ? accessorName : a.SoapAttribute.AttributeName);
                attribute.Namespace = a.SoapAttribute == null || a.SoapAttribute.Namespace == null ? ns : a.SoapAttribute.Namespace;
                attribute.Form = XmlSchemaForm.Qualified; // attributes are always qualified since they're only used for encoded soap headers
                attribute.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapAttribute == null ? String.Empty : a.SoapAttribute.DataType));
                attribute.Default = GetDefaultValue(model.FieldTypeDesc, a);
                accessor.Attribute = attribute;
                accessor.Elements = new ElementAccessor[0];
            }
            else {
                if ((flags & SoapAttributeFlags.Element) != flags)
                    throw new InvalidOperationException(Res.GetString(Res.XmlInvalidElementAttribute));

                ElementAccessor element = new ElementAccessor();
                element.IsSoap = true;
                element.Name = XmlConvert.EncodeLocalName(a.SoapElement == null || a.SoapElement.ElementName.Length == 0 ? accessorName : a.SoapElement.ElementName);
                element.Namespace = ns;
                element.Form = form;
                element.Mapping = ImportTypeMapping(modelScope.GetTypeModel(accessorType), (a.SoapElement == null ? String.Empty : a.SoapElement.DataType));
                if (a.SoapElement != null)
                    element.IsNullable = a.SoapElement.IsNullable;
                accessor.Elements = new ElementAccessor[] { element };
            }
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:40,代码来源:soapreflectionimporter.cs


示例7: ImportMemberMapping

 MemberMapping ImportMemberMapping(XmlReflectionMember xmlReflectionMember, string ns, XmlReflectionMember[] xmlReflectionMembers, XmlSchemaForm form) {
     SoapAttributes a = xmlReflectionMember.SoapAttributes;
     if (a.SoapIgnore) return null;
     MemberMapping member = new MemberMapping();
     member.IsSoap = true;
     member.Name = xmlReflectionMember.MemberName;
     bool checkSpecified = XmlReflectionImporter.FindSpecifiedMember(xmlReflectionMember.MemberName, xmlReflectionMembers) != null;
     FieldModel model = new FieldModel(xmlReflectionMember.MemberName, xmlReflectionMember.MemberType, typeScope.GetTypeDesc(xmlReflectionMember.MemberType), checkSpecified, false);
     member.CheckShouldPersist = model.CheckShouldPersist;
     member.CheckSpecified = model.CheckSpecified;
     member.ReadOnly = model.ReadOnly; // || !model.FieldTypeDesc.HasDefaultConstructor;
     ImportAccessorMapping(member, model, a, ns, form);
     if (xmlReflectionMember.OverrideIsNullable)
         member.Elements[0].IsNullable = false;
     return member;
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:16,代码来源:soapreflectionimporter.cs


示例8: PopulateMemberInfos

        private static void PopulateMemberInfos(StructMapping structMapping, MemberMapping[] memberMappings, System.Collections.Generic.Dictionary<string, MemberInfo> memberInfos)
        {
            memberInfos.Clear();
            for (int i = 0; i < memberMappings.Length; ++i)
            {
                memberInfos[memberMappings[i].Name] = memberMappings[i].MemberInfo;
                if (memberMappings[i].ChoiceIdentifier != null)
                    memberInfos[memberMappings[i].ChoiceIdentifier.MemberName] = memberMappings[i].ChoiceIdentifier.MemberInfo;
                if (memberMappings[i].CheckSpecifiedMemberInfo != null)
                    memberInfos[memberMappings[i].Name + "Specified"] = memberMappings[i].CheckSpecifiedMemberInfo;
            }

            // The scenario here is that user has one base class A and one derived class B and wants to serialize/deserialize an object of B.
            // There's one virtual property defined in A and overrided by B. Without the replacing logic below, the code generated will always
            // try to access the property defined in A, rather than B.
            // The logic here is to:
            // 1) Check current members inside memberInfos dictionary and figure out whether there's any override or new properties defined in the derived class.
            //    If so, replace the one on the base class with the one on the derived class.
            // 2) Do the same thing for the memberMapping array. Note that we need to create a new copy of MemberMapping object since the old one could still be referenced
            //    by the StructMapping of the baseclass, so updating it directly could lead to other issues.
            Dictionary<string, MemberInfo> replaceList = null;
            MemberInfo replacedInfo = null;
            foreach (KeyValuePair<string, MemberInfo> pair in memberInfos)
            {
                if (ShouldBeReplaced(pair.Value, structMapping.TypeDesc.Type, out replacedInfo))
                {
                    if (replaceList == null)
                    {
                        replaceList = new Dictionary<string, MemberInfo>();
                    }

                    replaceList.Add(pair.Key, replacedInfo);
                }
            }

            if (replaceList != null)
            {
                foreach (KeyValuePair<string, MemberInfo> pair in replaceList)
                {
                    memberInfos[pair.Key] = pair.Value;
                }
                for (int i = 0; i < memberMappings.Length; i++)
                {
                    MemberInfo mi;
                    if (replaceList.TryGetValue(memberMappings[i].Name, out mi))
                    {
                        MemberMapping newMapping = memberMappings[i].Clone();
                        newMapping.MemberInfo = mi;
                        memberMappings[i] = newMapping;
                    }
                }
            }
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:53,代码来源:Types.cs


示例9: WriteArray

        void WriteArray(string source, string arrayName, ArrayMapping arrayMapping, bool readOnly, bool isNullable, int fixupIndex) {
            if (arrayMapping.IsSoap) {
                Writer.Write("object rre = ");
                Writer.Write(fixupIndex >= 0 ? "ReadReferencingElement" : "ReadReferencedElement");
                Writer.Write("(");
                WriteID(arrayMapping.TypeName);
                Writer.Write(", ");
                WriteID(arrayMapping.Namespace);
                if (fixupIndex >= 0) {
                    Writer.Write(", ");
                    Writer.Write("out fixup.Ids[");
                    Writer.Write((fixupIndex).ToString(CultureInfo.InvariantCulture));
                    Writer.Write("]");
                }
                Writer.WriteLine(");");

                TypeDesc td = arrayMapping.TypeDesc;
                if (td.IsEnumerable || td.IsCollection) {
                    Writer.WriteLine("if (rre != null) {");
                    Writer.Indent++;
                    WriteAddCollectionFixup(td, readOnly, source, "rre");
                    Writer.Indent--;
                    Writer.WriteLine("}");
                }
                else {
                    Writer.WriteLine("try {");
                    Writer.Indent++;
                    WriteSourceBeginTyped(source, arrayMapping.TypeDesc);
                    Writer.Write("rre");
                    WriteSourceEnd(source);
                    Writer.WriteLine(";");
                    WriteCatchCastException(arrayMapping.TypeDesc, "rre", null);
                }
            }
            else {
                Writer.WriteLine("if (!ReadNull()) {");
                Writer.Indent++;

                MemberMapping memberMapping = new MemberMapping();
                memberMapping.Elements = arrayMapping.Elements;
                memberMapping.TypeDesc = arrayMapping.TypeDesc;
                memberMapping.ReadOnly = readOnly;
                Member member = new Member(this, source, arrayName, 0, memberMapping, false);
                member.IsNullable = false;//Note, [....]: IsNullable is set to false since null condition (xsi:nil) is already handled by 'ReadNull()'

                Member[] members = new Member[] { member };
                WriteMemberBegin(members);

                if (readOnly) {
                    Writer.Write("if (((object)(");
                    Writer.Write(member.ArrayName);
                    Writer.Write(") == null) || ");
                }
                else {
                    Writer.Write("if (");
                }
                Writer.WriteLine("(Reader.IsEmptyElement)) {");
                Writer.Indent++;
                Writer.WriteLine("Reader.Skip();");
                Writer.Indent--;
                Writer.WriteLine("}");
                Writer.WriteLine("else {");
                Writer.Indent++;

                Writer.WriteLine("Reader.ReadStartElement();");
                int loopIndex = WriteWhileNotLoopStart();
                Writer.Indent++;

                string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");";
                WriteMemberElements(members, unknownNode, unknownNode, null, null, null);
                Writer.WriteLine("Reader.MoveToContent();");

                WriteWhileLoopEnd(loopIndex);
                Writer.Indent--;
                Writer.WriteLine("ReadEndElement();");
                Writer.WriteLine("}");

                WriteMemberEnd(members, false);

                Writer.Indent--;
                Writer.WriteLine("}");
                if (isNullable) {
                    Writer.WriteLine("else {");
                    Writer.Indent++;
                    member.IsNullable = true;
                    WriteMemberBegin(members);
                    WriteMemberEnd(members);
                    Writer.Indent--;
                    Writer.WriteLine("}");
                }
            }
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:92,代码来源:XmlSerializationReader.cs


示例10: GenerateTypeElement

 string GenerateTypeElement(XmlTypeMapping xmlTypeMapping) {
     ElementAccessor element = xmlTypeMapping.Accessor;
     TypeMapping mapping = element.Mapping;
     string methodName = NextMethodName(element.Name);
     Writer.WriteLine();
     Writer.Write("public object ");
     Writer.Write(methodName);
     Writer.WriteLine("() {");
     Writer.Indent++;
     Writer.WriteLine("object o = null;");
     MemberMapping member = new MemberMapping();
     member.TypeDesc = mapping.TypeDesc;
     //member.ReadOnly = !mapping.TypeDesc.HasDefaultConstructor;
     member.Elements = new ElementAccessor[] { element };
     Member[] members = new Member[] { new Member(this,"o", "o", "a", 0, member) };
     Writer.WriteLine("Reader.MoveToContent();");
     string unknownNode = "UnknownNode(null, " + ExpectedElements(members) + ");";
     WriteMemberElements(members, "throw CreateUnknownNodeException();", unknownNode, element.Any ? members[0] : null,  null, null);
     if (element.IsSoap) {
         Writer.WriteLine("Referenced(o);");
         Writer.WriteLine("ReadReferencedElements();");
     }
     Writer.WriteLine("return (object)o;");
     Writer.Indent--;
     Writer.WriteLine("}");
     return methodName;
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:27,代码来源:XmlSerializationReader.cs


示例11: GetChoiceIdentifierSource

 string GetChoiceIdentifierSource(MemberMapping mapping, string parent, TypeDesc parentTypeDesc) {
     if (mapping.ChoiceIdentifier == null) return "";
     CodeIdentifier.CheckValidIdentifier(mapping.ChoiceIdentifier.MemberName);
     return RaCodeGen.GetStringForMember(parent,  mapping.ChoiceIdentifier.MemberName, parentTypeDesc);
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:5,代码来源:XmlSerializationReader.cs


示例12: AddMemberMetadata

        void AddMemberMetadata(CodeAttributeDeclarationCollection metadata, MemberMapping member, bool forceUseMemberName) {
            if (member.Elements.Length == 0) return;
            ElementAccessor element = member.Elements[0];
            TypeMapping mapping = (TypeMapping)element.Mapping;
            string elemName = Accessor.UnescapeName(element.Name);
            bool sameName = ((elemName == member.Name) && !forceUseMemberName);

            if (!sameName || mapping.TypeDesc.IsAmbiguousDataType || element.IsNullable) {
                AddElementMetadata(metadata, sameName ? null : elemName, mapping.TypeDesc.IsAmbiguousDataType ? mapping.TypeDesc : null, element.IsNullable);
            }
        }
开发者ID:ArildF,项目名称:masters,代码行数:11,代码来源:soapcodeexporter.cs


示例13: ExportProperty

        void ExportProperty(CodeTypeDeclaration codeClass, MemberMapping member, CodeIdentifiers memberScope) {
            string fieldName = memberScope.AddUnique(CodeExporter.MakeFieldName(member.Name), member);
            string fieldType = member.GetTypeName(CodeProvider);
            // need to create a private field
            CodeMemberField field = new CodeMemberField(fieldType, fieldName);
            field.Attributes = MemberAttributes.Private;
            codeClass.Members.Add(field);

            CodeMemberProperty prop = CreatePropertyDeclaration(field, member.Name, fieldType);
            prop.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
            AddMemberMetadata(prop.CustomAttributes, member, false);
            codeClass.Members.Add(prop);

            if (member.CheckSpecified != SpecifiedAccessor.None) {
                field = new CodeMemberField(typeof(bool).FullName, fieldName + "Specified");
                field.Attributes = MemberAttributes.Private;
                codeClass.Members.Add(field);
                
                prop = CreatePropertyDeclaration(field, member.Name + "Specified", typeof(bool).FullName);
                prop.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapIgnoreAttribute).FullName);
                prop.CustomAttributes.Add(attribute);
                codeClass.Members.Add(prop);
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:25,代码来源:SoapCodeExporter.cs


示例14: ExportMember

        void ExportMember(CodeTypeDeclaration codeClass, MemberMapping member) {
            string fieldType = member.GetTypeName(CodeProvider);
            CodeMemberField field = new CodeMemberField(fieldType, member.Name);
            field.Attributes = (field.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
            field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
            codeClass.Members.Add(field);
            AddMemberMetadata(field.CustomAttributes, member, false);

            if (member.CheckSpecified != SpecifiedAccessor.None) {
                field = new CodeMemberField(typeof(bool).FullName, member.Name + "Specified");
                field.Attributes = (field.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
                field.Comments.Add(new CodeCommentStatement(Res.GetString(Res.XmlRemarks), true));
                CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(SoapIgnoreAttribute).FullName);
                field.CustomAttributes.Add(attribute);
                codeClass.Members.Add(field);
            }
        }
开发者ID:uQr,项目名称:referencesource,代码行数:17,代码来源:SoapCodeExporter.cs


示例15: MemberMapping

 MemberMapping(MemberMapping mapping)
     : base(mapping)
 {
     this.name = mapping.name;
     this.checkShouldPersist = mapping.checkShouldPersist;
     this.checkSpecified = mapping.checkSpecified;
     this.isReturnValue = mapping.isReturnValue;
     this.readOnly = mapping.readOnly;
     this.sequenceId = mapping.sequenceId;
     this.memberInfo = mapping.memberInfo;
     this.checkSpecifiedMemberInfo = mapping.checkSpecifiedMemberInfo;
     this.checkShouldPersistMethodInfo = mapping.checkShouldPersistMethodInfo;
 }
开发者ID:uQr,项目名称:referencesource,代码行数:13,代码来源:Mappings.cs


示例16: Member

 internal Member(XmlSerializationReaderCodeGen outerClass, string source, string arrayName, int i, MemberMapping mapping, bool multiRef)
     : this(outerClass, source, null, arrayName, i, mapping, multiRef, null) {
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:3,代码来源:XmlSerializationReader.cs


示例17: ExportMember

 void ExportMember(CodeTypeDeclaration codeClass, MemberMapping member) {
     CodeAttributeDeclarationCollection metadata = new CodeAttributeDeclarationCollection();
     CodeMemberField field = new CodeMemberField(member.TypeDesc.FullName, member.Name);
     field.Attributes = (field.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;
     field.Comments.Add(new CodeCommentStatement("<remarks/>", true));
     codeClass.Members.Add(field);
     AddMemberMetadata(metadata, member, false);
     field.CustomAttributes = metadata;
 }
开发者ID:ArildF,项目名称:masters,代码行数:9,代码来源:soapcodeexporter.cs


示例18: InitializeValueTypes

        void InitializeValueTypes(string arrayName, MemberMapping[] mappings) {
            for (int i = 0; i < mappings.Length; i++) {
                if (!mappings[i].TypeDesc.IsValueType)
                    continue;
                Writer.Write(arrayName);
                Writer.Write("[");
                Writer.Write(i.ToString(CultureInfo.InvariantCulture));
                Writer.Write("] = ");

                if (mappings[i].TypeDesc.IsOptionalValue && mappings[i].TypeDesc.BaseTypeDesc.UseReflection) {
                    Writer.Write("null");
                }
                else {
                    Writer.Write(RaCodeGen.GetStringForCreateInstance(mappings[i].TypeDesc.CSharpName, mappings[i].TypeDesc.UseReflection, false, false));
                }
                Writer.WriteLine(";");
            }
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:18,代码来源:XmlSerializationReader.cs


示例19: FindDeclaringMapping

        internal MemberMapping FindDeclaringMapping(MemberMapping member, out StructMapping declaringMapping, string parent)
        {
            declaringMapping = null;
            if (BaseMapping != null)
            {
                MemberMapping baseMember = BaseMapping.FindDeclaringMapping(member, out declaringMapping, parent);
                if (baseMember != null) return baseMember;
            }
            if (_members == null) return null;

            for (int i = 0; i < _members.Length; i++)
            {
                if (_members[i].Name == member.Name)
                {
                    if (_members[i].TypeDesc != member.TypeDesc)
                        throw new InvalidOperationException(SR.Format(SR.XmlHiddenMember, parent, member.Name, member.TypeDesc.FullName, this.TypeName, _members[i].Name, _members[i].TypeDesc.FullName));
                    else if (!_members[i].Match(member))
                    {
                        throw new InvalidOperationException(SR.Format(SR.XmlInvalidXmlOverride, parent, member.Name, this.TypeName, _members[i].Name));
                    }
                    declaringMapping = this;
                    return _members[i];
                }
            }
            return null;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:26,代码来源:Mappings.cs


示例20: WriteEnumAndArrayTypes

        void WriteEnumAndArrayTypes() {
            foreach (TypeScope scope in Scopes) {
                foreach (Mapping m in scope.TypeMappings) {
                    if (m.IsSoap)
                        continue;
                    if (m is EnumMapping) {
                        EnumMapping mapping = (EnumMapping)m;
                        Writer.Write("else if (");
                        WriteQNameEqual("xsiType", mapping.TypeName, mapping.Namespace);
                        Writer.WriteLine(") {");
                        Writer.Indent++;
                        Writer.WriteLine("Reader.ReadStartElement();");
                        string methodName = ReferenceMapping(mapping);
                        #if DEBUG
                            // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
                            if (methodName == null) throw new InvalidOperationException(Res.GetString(Res.XmlInternalErrorMethod, mapping.TypeDesc.Name));
                        #endif
                        Writer.Write("object e = ");
                        Writer.Write(methodName);
                        Writer.WriteLine("(CollapseWhitespace(Reader.ReadString()));");
                        Writer.WriteLine("ReadEndElement();");
                        Writer.WriteLine("return e;");
                        Writer.Indent--;
                        Writer.WriteLine("}");
                    }
                    else if (m is ArrayMapping) {
                        ArrayMapping mapping = (ArrayMapping) m;
                        if (mapping.TypeDesc.HasDefaultConstructor) {
                            Writer.Write("else if (");
                            WriteQNameEqual("xsiType", mapping.TypeName, mapping.Namespace);
                            Writer.WriteLine(") {");
                            Writer.Indent++;
                            MemberMapping memberMapping = new MemberMapping();
                            memberMapping.TypeDesc = mapping.TypeDesc;
                            memberMapping.Elements = mapping.Elements;
                            Member member = new Member(this,"a", "z", 0, memberMapping);

                            TypeDesc td = mapping.TypeDesc;
                            string fullTypeName = mapping.TypeDesc.CSharpName;
                            if (td.UseReflection){
                                if (td.IsArray)
                                    Writer.Write(typeof(Array).FullName);
                                else
                                    Writer.Write("object");
                            }
                            else
                                Writer.Write(fullTypeName);
                            Writer.Write(" a = ");
                            if (mapping.TypeDesc.IsValueType) {
                                Writer.Write(RaCodeGen.GetStringForCreateInstance(fullTypeName, td.UseReflection, false, false));
                                Writer.WriteLine(";");
                            }
                            else
                                Writer.WriteLine("null;");

                            WriteArray(member.Source, member.ArrayName, mapping, false, false, -1);
                            Writer.WriteLine("return a;");
                            Writer.Indent--;
                            Writer.WriteLine("}");
                        }
                    }
                }
            }
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:64,代码来源:XmlSerializationReader.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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