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

C# Serialization.ChoiceIdentifierAccessor类代码示例

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

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



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

示例1: WriteElements

        void WriteElements(string source, string enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, string arrayName, bool writeAccessors, bool isNullable) {
            if (elements.Length == 0 && text == null) return;
            if (elements.Length == 1 && text == null) {
                TypeDesc td = elements[0].IsUnbounded ? elements[0].Mapping.TypeDesc.CreateArrayTypeDesc() : elements[0].Mapping.TypeDesc;
                if (!elements[0].Any && !elements[0].Mapping.TypeDesc.UseReflection && !elements[0].Mapping.TypeDesc.IsOptionalValue)
                    source = "(("+td.CSharpName+")"+ source+")";
                WriteElement(source, elements[0], arrayName, writeAccessors);
            }
            else {
                if (isNullable && choice == null) {
                    Writer.Write("if ((object)(");
                    Writer.Write(source);
                    Writer.Write(") != null)");
                }
                Writer.WriteLine("{");
                Writer.Indent++;
                int anyCount = 0;
                ArrayList namedAnys = new ArrayList();
                ElementAccessor unnamedAny = null; // can only have one
                bool wroteFirstIf = false;
                string enumTypeName = choice == null ? null : choice.Mapping.TypeDesc.FullName;

                for (int i = 0; i < elements.Length; i++) {
                    ElementAccessor element = elements[i];

                    if (element.Any) {
                        anyCount++;
                        if (element.Name != null && element.Name.Length > 0)
                            namedAnys.Add(element);
                        else if (unnamedAny == null)
                            unnamedAny = element;
                    }
                    else if (choice != null) {
                        bool useReflection = element.Mapping.TypeDesc.UseReflection;
                        string fullTypeName = element.Mapping.TypeDesc.CSharpName;
                        bool enumUseReflection = choice.Mapping.TypeDesc.UseReflection;
                        string enumFullName = (enumUseReflection?"":enumTypeName + "[email protected]") + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, enumUseReflection);

                        if (wroteFirstIf) Writer.Write("else ");
                        else wroteFirstIf = true;
                        Writer.Write("if (");
                        Writer.Write(enumUseReflection?RaCodeGen.GetStringForEnumLongValue(enumSource, enumUseReflection):enumSource);
                        Writer.Write(" == ");
                        Writer.Write(enumFullName);
                        if (isNullable && !element.IsNullable) {
                            Writer.Write(" && ((object)(");
                            Writer.Write(source);
                            Writer.Write(") != null)");
                        }
                        Writer.WriteLine(") {");
                        Writer.Indent++;

                        WriteChoiceTypeCheck(source, fullTypeName, useReflection, choice, enumFullName, element.Mapping.TypeDesc);

                        string castedSource = source;
                        if (!useReflection)
                            castedSource = "(("+fullTypeName+")"+ source+")";
                        WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
                        Writer.Indent--;
                        Writer.WriteLine("}");
                    }
                    else {
                        bool useReflection = element.Mapping.TypeDesc.UseReflection;
                        TypeDesc td = element.IsUnbounded ? element.Mapping.TypeDesc.CreateArrayTypeDesc() : element.Mapping.TypeDesc;
                        string fullTypeName = td.CSharpName;
                        if (wroteFirstIf) Writer.Write("else ");
                        else wroteFirstIf = true;
                        Writer.Write("if (");
                        WriteInstanceOf(source, fullTypeName, useReflection);
                        Writer.WriteLine(") {");
                        Writer.Indent++;
                        string castedSource = source;
                        if (!useReflection)
                            castedSource = "(("+fullTypeName+")"+ source+")";
                        WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
                        Writer.Indent--;
                        Writer.WriteLine("}");
                    }
                }
                if (anyCount > 0) {
                    if (elements.Length - anyCount > 0) Writer.Write("else ");
                    
                    string fullTypeName = typeof(XmlElement).FullName;

                    Writer.Write("if (");
                    Writer.Write(source);
                    Writer.Write(" is ");
                    Writer.Write(fullTypeName);
                    Writer.WriteLine(") {");
                    Writer.Indent++;

                    Writer.Write(fullTypeName);
                    Writer.Write(" elem = (");
                    Writer.Write(fullTypeName);
                    Writer.Write(")");
                    Writer.Write(source);
                    Writer.WriteLine(";");
                    
                    int c = 0;

//.........这里部分代码省略.........
开发者ID:uQr,项目名称:referencesource,代码行数:101,代码来源:XmlSerializationWriter.cs


示例2: WriteArray

 private void WriteArray(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc)
 {
     if ((elements.Length != 0) || (text != null))
     {
         base.Writer.WriteLine("{");
         IndentedWriter writer = base.Writer;
         writer.Indent++;
         string cSharpName = arrayTypeDesc.CSharpName;
         this.WriteArrayLocalDecl(cSharpName, "a", source, arrayTypeDesc);
         if (arrayTypeDesc.IsNullable)
         {
             base.Writer.WriteLine("if (a != null) {");
             IndentedWriter writer2 = base.Writer;
             writer2.Indent++;
         }
         if (choice != null)
         {
             bool useReflection = choice.Mapping.TypeDesc.UseReflection;
             this.WriteArrayLocalDecl(choice.Mapping.TypeDesc.CSharpName + "[]", "c", choiceSource, choice.Mapping.TypeDesc);
             base.Writer.WriteLine("if (c == null || c.Length < a.Length) {");
             IndentedWriter writer3 = base.Writer;
             writer3.Indent++;
             base.Writer.Write("throw CreateInvalidChoiceIdentifierValueException(");
             base.WriteQuotedCSharpString(choice.Mapping.TypeDesc.FullName);
             base.Writer.Write(", ");
             base.WriteQuotedCSharpString(choice.MemberName);
             base.Writer.Write(");");
             IndentedWriter writer4 = base.Writer;
             writer4.Indent--;
             base.Writer.WriteLine("}");
         }
         this.WriteArrayItems(elements, text, choice, arrayTypeDesc, "a", "c");
         if (arrayTypeDesc.IsNullable)
         {
             IndentedWriter writer5 = base.Writer;
             writer5.Indent--;
             base.Writer.WriteLine("}");
         }
         IndentedWriter writer6 = base.Writer;
         writer6.Indent--;
         base.Writer.WriteLine("}");
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:43,代码来源:XmlSerializationWriterCodeGen.cs


示例3: WriteMember

 void WriteMember(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors) {
     if (memberTypeDesc.IsArrayLike && 
         !(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
         WriteArray(source, choiceSource, elements, text, choice, memberTypeDesc);
     else
         WriteElements(source, choiceSource, elements, text, choice, "a", writeAccessors, memberTypeDesc.IsNullable);
 }
开发者ID:uQr,项目名称:referencesource,代码行数:7,代码来源:XmlSerializationWriter.cs


示例4: WriteArrayItems

        void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName) {
            TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;

            if (arrayTypeDesc.IsEnumerable) {
                Writer.Write(typeof(IEnumerator).FullName);
                Writer.Write(" e = ");
                if (arrayTypeDesc.IsPrivateImplementation) {
                    Writer.Write("((");
                    Writer.Write(typeof(IEnumerable).FullName);
                    Writer.Write(")");
                    Writer.Write(arrayName);
                    Writer.WriteLine(").GetEnumerator();");
                }
                else if(arrayTypeDesc.IsGenericInterface) {
                    if (arrayTypeDesc.UseReflection) {
                        // we use wildcard method name for generic GetEnumerator method, so we cannot use GetStringForMethodInvoke call here
                        Writer.Write("(");
                        Writer.Write(typeof(IEnumerator).FullName);
                        Writer.Write(")");
                        Writer.Write(RaCodeGen.GetReflectionVariable(arrayTypeDesc.CSharpName, "System.Collections.Generic.IEnumerable*"));
                        Writer.Write(".Invoke(");
                        Writer.Write(arrayName);
                        Writer.WriteLine(", new object[0]);");
                    }
                    else {
                        Writer.Write("((System.Collections.Generic.IEnumerable<");
                        Writer.Write(arrayElementTypeDesc.CSharpName);
                        Writer.Write(">)");
                        Writer.Write(arrayName);
                        Writer.WriteLine(").GetEnumerator();");
                    }
                }
                else {
                    if (arrayTypeDesc.UseReflection) {
                        Writer.Write("(");
                        Writer.Write(typeof(IEnumerator).FullName);
                        Writer.Write(")");
                    }
                    Writer.Write(RaCodeGen.GetStringForMethodInvoke(arrayName, arrayTypeDesc.CSharpName, "GetEnumerator", arrayTypeDesc.UseReflection));
                    Writer.WriteLine(";");
                }
                Writer.WriteLine("if (e != null)");
                Writer.WriteLine("while (e.MoveNext()) {");
                Writer.Indent++;
                string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
                WriteLocalDecl(arrayTypeFullName, arrayName+"i", "e.Current", arrayElementTypeDesc.UseReflection);
                WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true);
            }
            else {
                Writer.Write("for (int i");
                Writer.Write(arrayName);
                Writer.Write(" = 0; i");
                Writer.Write(arrayName);
                Writer.Write(" < ");
                if (arrayTypeDesc.IsArray) {
                    Writer.Write(arrayName);
                    Writer.Write(".Length");
                }
                else {
                    Writer.Write("((");
                    Writer.Write(typeof(ICollection).FullName);
                    Writer.Write(")");
                    Writer.Write(arrayName);
                    Writer.Write(").Count");
                }
                Writer.Write("; i");
                Writer.Write(arrayName);
                Writer.WriteLine("++) {");
                Writer.Indent++;
                int count = elements.Length + (text == null ? 0 : 1);
                if (count > 1) {
                    string arrayTypeFullName = arrayElementTypeDesc.CSharpName;
                    WriteLocalDecl(arrayTypeFullName, arrayName+"i", RaCodeGen.GetStringForArrayMember(arrayName, "i"+arrayName, arrayTypeDesc), arrayElementTypeDesc.UseReflection);
                    if (choice != null) {
                        string choiceFullName = choice.Mapping.TypeDesc.CSharpName;
                        WriteLocalDecl(choiceFullName, choiceName+"i", RaCodeGen.GetStringForArrayMember(choiceName, "i"+arrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection);
                    }
                    WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
                }
                else {
                    WriteElements(RaCodeGen.GetStringForArrayMember(arrayName , "i" + arrayName, arrayTypeDesc), elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
                }
            }
            Writer.Indent--;
            Writer.WriteLine("}");
        }
开发者ID:uQr,项目名称:referencesource,代码行数:86,代码来源:XmlSerializationWriter.cs


示例5: WriteElements

        private void WriteElements(object o, object enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, string arrayName, bool writeAccessors, bool isNullable, XmlMapping parentMapping = null)
        {
            if (elements.Length == 0 && text == null) return;
            if (elements.Length == 1 && text == null)
            {
                WriteElement(o, elements[0], arrayName, writeAccessors, parentMapping);
            }
            else
            {
                if (isNullable && choice == null && o == null)
                {
                    return;
                }

                int anyCount = 0;
                var namedAnys = new List<ElementAccessor>();
                ElementAccessor unnamedAny = null; // can only have one
                string enumTypeName = choice == null ? null : choice.Mapping.TypeDesc.FullName;

                for (int i = 0; i < elements.Length; i++)
                {
                    ElementAccessor element = elements[i];

                    if (element.Any)
                    {
                        anyCount++;
                        if (element.Name != null && element.Name.Length > 0)
                            namedAnys.Add(element);
                        else if (unnamedAny == null)
                            unnamedAny = element;
                    }
                    else if (choice != null)
                    {
                        if (o != null && o.GetType() == element.Mapping.TypeDesc.Type)
                        {
                            WriteElement(o, element, arrayName, writeAccessors);
                            return;
                        }
                    }
                    else
                    {
                        TypeDesc td = element.IsUnbounded ? element.Mapping.TypeDesc.CreateArrayTypeDesc() : element.Mapping.TypeDesc;
                        if (o.GetType() == td.Type)
                        {
                            WriteElement(o, element, arrayName, writeAccessors);
                            return;
                        }
                    }
                }

                if (anyCount > 0)
                {
                    var elem = o as XmlElement;
                    if (elem != null)
                    {
                        foreach (ElementAccessor element in namedAnys)
                        {
                            if (element.Name == elem.Name && element.Namespace == elem.NamespaceURI)
                            {
                                WriteElement(elem, element, arrayName, writeAccessors);
                                return;
                            }
                        }

                        if (choice != null)
                        {
                            throw CreateChoiceIdentifierValueException(choice.Mapping.TypeDesc.FullName, choice.MemberName, elem.Name, elem.NamespaceURI);
                        }

                        if (unnamedAny != null)
                        {
                            WriteElement(elem, unnamedAny, arrayName, writeAccessors);
                            return;
                        }

                        throw CreateUnknownAnyElementException(elem.Name, elem.NamespaceURI);
                    }
                }

                if (text != null)
                {
                    bool useReflection = text.Mapping.TypeDesc.UseReflection;
                    string fullTypeName = text.Mapping.TypeDesc.CSharpName;
                    WriteText(o, text);
                    return;
                }

                if (elements.Length > 0 && o != null)
                {
                    throw CreateUnknownTypeException(o);
                }
            }
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:93,代码来源:ReflectionXmlSerializationWriter.cs


示例6: WriteChoiceTypeCheck

        void WriteChoiceTypeCheck(string source, string fullTypeName, ChoiceIdentifierAccessor choice, string enumName) {

            writer.Write("if (((object)");
            writer.Write(source);
            writer.Write(") != null && !(");
            writer.Write(source);
            writer.Write(" is ");
            writer.Write(fullTypeName);
            writer.Write(")) throw CreateMismatchChoiceException(");
            WriteQuotedCSharpString(fullTypeName);
            writer.Write(", ");
            WriteQuotedCSharpString(choice.MemberName);
            writer.Write(", ");
            WriteQuotedCSharpString(enumName);
            writer.WriteLine(");");
        }
开发者ID:ArildF,项目名称:masters,代码行数:16,代码来源:xmlserializationwriter.cs


示例7: WriteArray

        private void WriteArray(object o, object choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc)
        {
            if (elements.Length == 0 && text == null)
            {
                return;
            }

            if (arrayTypeDesc.IsNullable && o == null)
            {
                return;
            }

            if (choice != null)
            {
                if (choiceSource == null || ((Array)choiceSource).Length < ((Array)o).Length)
                {
                    throw CreateInvalidChoiceIdentifierValueException(choice.Mapping.TypeDesc.FullName, choice.MemberName);
                }
            }

            WriteArrayItems(elements, text, choice, arrayTypeDesc, o);
        }
开发者ID:geoffkizer,项目名称:corefx,代码行数:22,代码来源:ReflectionXmlSerializationWriter.cs


示例8: WriteArrayItems

        void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName) {
            TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;

            if (arrayTypeDesc.IsEnumerable) {
                writer.Write(typeof(IEnumerator).FullName);
                writer.Write(" e = ");
                writer.Write(arrayName);
                writer.WriteLine(".GetEnumerator();");
                writer.WriteLine("if (e != null)");
                writer.WriteLine("while (e.MoveNext()) {");
                writer.Indent++;
                string arrayElementTypeName = CodeIdentifier.EscapeKeywords(arrayElementTypeDesc.FullName);
                writer.Write(arrayElementTypeName);
                writer.Write(" ");
                writer.Write(arrayName);
                writer.Write("i = (");
                writer.Write(arrayElementTypeName);
                writer.WriteLine(")e.Current;");
                WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true);
            }
            else {
                writer.Write("for (int i");
                writer.Write(arrayName);
                writer.Write(" = 0; i");
                writer.Write(arrayName);
                writer.Write(" < ");
                writer.Write(arrayName);
                writer.Write(".");
                writer.Write(arrayTypeDesc.ArrayLengthName);
                writer.Write("; i");
                writer.Write(arrayName);
                writer.WriteLine("++) {");
                writer.Indent++;
                int count = elements.Length + (text == null ? 0 : 1);
                if (count > 1) {
                    writer.Write(CodeIdentifier.EscapeKeywords(arrayElementTypeDesc.FullName));
                    writer.Write(" ");
                    writer.Write(arrayName);
                    writer.Write("i = ");
                    writer.Write(arrayName);
                    writer.Write("[i");
                    writer.Write(arrayName);
                    writer.WriteLine("];");
                    if (choice != null) {
                        writer.Write(CodeIdentifier.EscapeKeywords(choice.Mapping.TypeDesc.FullName));
                        writer.Write(" ");
                        writer.Write(choiceName);
                        writer.Write("i = ");
                        writer.Write(choiceName);
                        writer.Write("[i");
                        writer.Write(arrayName);
                        writer.WriteLine("];");
                    }
                    WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
                }
                else {
                    WriteElements(arrayName + "[i" + arrayName + "]", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
                }
            }
            writer.Indent--;
            writer.WriteLine("}");
        }
开发者ID:ArildF,项目名称:masters,代码行数:62,代码来源:xmlserializationwriter.cs


示例9: WriteElements

        void WriteElements(string source, string enumSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, string arrayName, bool writeAccessors, bool isNullable) {
            if (elements.Length == 0 && text == null) return;
            if (elements.Length == 1 && text == null) {
                WriteElement("((" + CodeIdentifier.EscapeKeywords(((TypeMapping)elements[0].Mapping).TypeDesc.FullName) + ")" + source + ")", elements[0], arrayName, writeAccessors);
            }
            else {
                writer.WriteLine("{");
                writer.Indent++;
                int anyCount = 0;
                ArrayList namedAnys = new ArrayList();
                ElementAccessor unnamedAny = null; // can only have one
                bool wroteFirstIf = false;
                for (int i = 0; i < elements.Length; i++) {
                    ElementAccessor element = elements[i];
                    if (choice != null) {
                        string fullTypeName = CodeIdentifier.EscapeKeywords(((TypeMapping)element.Mapping).TypeDesc.FullName);
                        string enumTypeName = CodeIdentifier.EscapeKeywords(choice.Mapping.TypeDesc.FullName);
                        string enumFullName = enumTypeName + "[email protected]";

                        string enumValue = null;
                        EnumMapping choiceMapping = (EnumMapping)choice.Mapping;
                        for (int j = 0; j < choiceMapping.Constants.Length; j++) {
                            string xmlName = choiceMapping.Constants[j].XmlName;
                            int colon = xmlName.LastIndexOf(':');
                            string choiceNs = colon < 0 ? element.Namespace : xmlName.Substring(0, colon);
                            string choiceName = colon < 0 ? xmlName : xmlName.Substring(colon+1);
                            if (element.Name == choiceName && element.Namespace == choiceNs) {
                                enumValue = choiceMapping.Constants[j].Name;
                                break;
                            }
                        }
                        if (enumValue == null || enumValue.Length == 0) {
                            // Type {0} is missing value for '{1}'.
                            throw new InvalidOperationException(Res.GetString(Res.XmlChoiceMissingValue, choiceMapping.TypeDesc.FullName, element.Name));
                        }
                        enumFullName += enumValue;

                        if (wroteFirstIf) writer.Write("else ");
                        else wroteFirstIf = true;
                        writer.Write("if (");
                        writer.Write(enumSource);
                        writer.Write(" == ");
                        writer.Write(enumFullName);
                        writer.WriteLine(") {");
                        writer.Indent++;

                        WriteChoiceTypeCheck(source, fullTypeName, choice, enumFullName);

                        WriteElement("((" + fullTypeName + ")" + source + ")", element, arrayName, writeAccessors);
                        writer.Indent--;
                        writer.WriteLine("}");
                    }
                    else if (element.Any) {
                        anyCount++;
                        if (element.Name != null && element.Name.Length > 0)
                            namedAnys.Add(element);
                        else if (unnamedAny == null)
                            unnamedAny = element;
                    }
                    else {
                        string fullTypeName = CodeIdentifier.EscapeKeywords(((TypeMapping)element.Mapping).TypeDesc.FullName);
                        if (wroteFirstIf) writer.Write("else ");
                        else wroteFirstIf = true;
                        writer.Write("if (");
                        writer.Write(source);
                        writer.Write(" is ");
                        writer.Write(fullTypeName);
                        writer.WriteLine(") {");
                        writer.Indent++;
                        WriteElement("((" + fullTypeName + ")" + source + ")", element, arrayName, writeAccessors);
                        writer.Indent--;
                        writer.WriteLine("}");
                    }
                }
                if (anyCount > 0) {
                    if (elements.Length - anyCount > 0) writer.Write("else ");
                    
                    string fullTypeName = typeof(XmlElement).FullName;

                    writer.Write("if (");
                    writer.Write(source);
                    writer.Write(" is ");
                    writer.Write(fullTypeName);
                    writer.WriteLine(") {");
                    writer.Indent++;

                    writer.Write(fullTypeName);
                    writer.Write(" elem = (");
                    writer.Write(fullTypeName);
                    writer.Write(")");
                    writer.Write(source);
                    writer.WriteLine(";");
                    
                    int c = 0;
                    foreach (ElementAccessor element in namedAnys) {
                        if (c++ > 0) writer.Write("else ");
                        writer.Write("if (elem.Name == ");
                        WriteQuotedCSharpString(element.Name);
                        writer.Write(" && elem.NamespaceURI == ");
                        WriteQuotedCSharpString(element.Namespace);
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:xmlserializationwriter.cs


示例10: WriteArray

        void WriteArray(string source, string choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc) {
            if (elements.Length == 0 && text == null) return;
            writer.WriteLine("{");
            writer.Indent++;
            string arrayTypeName = CodeIdentifier.EscapeKeywords(arrayTypeDesc.FullName);
            writer.Write(arrayTypeName);
            writer.Write(" a = (");
            writer.Write(arrayTypeName);
            writer.Write(")");
            writer.Write(source);
            writer.WriteLine(";");
            if (arrayTypeDesc.IsNullable) {
                writer.WriteLine("if (a != null) {");
                writer.Indent++;
            }

            if (choice != null) {
                writer.Write(CodeIdentifier.EscapeKeywords(choice.Mapping.TypeDesc.FullName));
                writer.Write("[] c = ");
                writer.Write(choiceSource);
                writer.WriteLine(";");
            }

            WriteArrayItems(elements, text, choice, arrayTypeDesc, "a", "c");
            if (arrayTypeDesc.IsNullable) {
                writer.Indent--;
                writer.WriteLine("}");
            }
            writer.Indent--;
            writer.WriteLine("}");
        }
开发者ID:ArildF,项目名称:masters,代码行数:31,代码来源:xmlserializationwriter.cs


示例11: WriteElement

 private void WriteElement(string source, string arrayName, string choiceSource, ElementAccessor element, ChoiceIdentifierAccessor choice, string checkSpecified, bool checkForNull, bool readOnly, int fixupIndex, int elementIndex)
 {
     if ((checkSpecified != null) && (checkSpecified.Length > 0))
     {
         base.Writer.Write(checkSpecified);
         base.Writer.WriteLine(" = true;");
     }
     if (element.Mapping is ArrayMapping)
     {
         this.WriteArray(source, arrayName, (ArrayMapping) element.Mapping, readOnly, element.IsNullable, fixupIndex);
     }
     else if (element.Mapping is NullableMapping)
     {
         string s = base.ReferenceMapping(element.Mapping);
         this.WriteSourceBegin(source);
         base.Writer.Write(s);
         base.Writer.Write("(true)");
         this.WriteSourceEnd(source);
         base.Writer.WriteLine(";");
     }
     else if (!element.Mapping.IsSoap && (element.Mapping is PrimitiveMapping))
     {
         if (element.IsNullable)
         {
             base.Writer.WriteLine("if (ReadNull()) {");
             IndentedWriter writer1 = base.Writer;
             writer1.Indent++;
             this.WriteSourceBegin(source);
             if (element.Mapping.TypeDesc.IsValueType)
             {
                 base.Writer.Write(base.RaCodeGen.GetStringForCreateInstance(element.Mapping.TypeDesc.CSharpName, element.Mapping.TypeDesc.UseReflection, false, false));
             }
             else
             {
                 base.Writer.Write("null");
             }
             this.WriteSourceEnd(source);
             base.Writer.WriteLine(";");
             IndentedWriter writer2 = base.Writer;
             writer2.Indent--;
             base.Writer.WriteLine("}");
             base.Writer.Write("else ");
         }
         if (((element.Default != null) && (element.Default != DBNull.Value)) && element.Mapping.TypeDesc.IsValueType)
         {
             base.Writer.WriteLine("if (Reader.IsEmptyElement) {");
             IndentedWriter writer3 = base.Writer;
             writer3.Indent++;
             base.Writer.WriteLine("Reader.Skip();");
             IndentedWriter writer4 = base.Writer;
             writer4.Indent--;
             base.Writer.WriteLine("}");
             base.Writer.WriteLine("else {");
         }
         else
         {
             base.Writer.WriteLine("{");
         }
         IndentedWriter writer = base.Writer;
         writer.Indent++;
         this.WriteSourceBegin(source);
         if (element.Mapping.TypeDesc == base.QnameTypeDesc)
         {
             base.Writer.Write("ReadElementQualifiedName()");
         }
         else
         {
             string str2;
             string str5;
             if (((str5 = element.Mapping.TypeDesc.FormatterName) != null) && ((str5 == "ByteArrayBase64") || (str5 == "ByteArrayHex")))
             {
                 str2 = "false";
             }
             else
             {
                 str2 = "Reader.ReadElementString()";
             }
             this.WritePrimitive(element.Mapping, str2);
         }
         this.WriteSourceEnd(source);
         base.Writer.WriteLine(";");
         IndentedWriter writer6 = base.Writer;
         writer6.Indent--;
         base.Writer.WriteLine("}");
     }
     else if ((element.Mapping is StructMapping) || (element.Mapping.IsSoap && (element.Mapping is PrimitiveMapping)))
     {
         TypeMapping mapping = element.Mapping;
         if (mapping.IsSoap)
         {
             base.Writer.Write("object rre = ");
             base.Writer.Write((fixupIndex >= 0) ? "ReadReferencingElement" : "ReadReferencedElement");
             base.Writer.Write("(");
             this.WriteID(mapping.TypeName);
             base.Writer.Write(", ");
             this.WriteID(mapping.Namespace);
             if (fixupIndex >= 0)
             {
                 base.Writer.Write(", out fixup.Ids[");
                 base.Writer.Write(fixupIndex.ToString(CultureInfo.InvariantCulture));
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:XmlSerializationReaderCodeGen.cs


示例12: WriteArrayItems

 private void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName)
 {
     TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
     if (arrayTypeDesc.IsEnumerable)
     {
         base.Writer.Write(typeof(IEnumerator).FullName);
         base.Writer.Write(" e = ");
         if (arrayTypeDesc.IsPrivateImplementation)
         {
             base.Writer.Write("((");
             base.Writer.Write(typeof(IEnumerable).FullName);
             base.Writer.Write(")");
             base.Writer.Write(arrayName);
             base.Writer.WriteLine(").GetEnumerator();");
         }
         else if (arrayTypeDesc.IsGenericInterface)
         {
             if (arrayTypeDesc.UseReflection)
             {
                 base.Writer.Write("(");
                 base.Writer.Write(typeof(IEnumerator).FullName);
                 base.Writer.Write(")");
                 base.Writer.Write(base.RaCodeGen.GetReflectionVariable(arrayTypeDesc.CSharpName, "System.Collections.Generic.IEnumerable*"));
                 base.Writer.Write(".Invoke(");
                 base.Writer.Write(arrayName);
                 base.Writer.WriteLine(", new object[0]);");
             }
             else
             {
                 base.Writer.Write("((System.Collections.Generic.IEnumerable<");
                 base.Writer.Write(arrayElementTypeDesc.CSharpName);
                 base.Writer.Write(">)");
                 base.Writer.Write(arrayName);
                 base.Writer.WriteLine(").GetEnumerator();");
             }
         }
         else
         {
             if (arrayTypeDesc.UseReflection)
             {
                 base.Writer.Write("(");
                 base.Writer.Write(typeof(IEnumerator).FullName);
                 base.Writer.Write(")");
             }
             base.Writer.Write(base.RaCodeGen.GetStringForMethodInvoke(arrayName, arrayTypeDesc.CSharpName, "GetEnumerator", arrayTypeDesc.UseReflection, new string[0]));
             base.Writer.WriteLine(";");
         }
         base.Writer.WriteLine("if (e != null)");
         base.Writer.WriteLine("while (e.MoveNext()) {");
         IndentedWriter writer1 = base.Writer;
         writer1.Indent++;
         string cSharpName = arrayElementTypeDesc.CSharpName;
         this.WriteLocalDecl(cSharpName, arrayName + "i", "e.Current", arrayElementTypeDesc.UseReflection);
         this.WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, true);
     }
     else
     {
         base.Writer.Write("for (int i");
         base.Writer.Write(arrayName);
         base.Writer.Write(" = 0; i");
         base.Writer.Write(arrayName);
         base.Writer.Write(" < ");
         if (arrayTypeDesc.IsArray)
         {
             base.Writer.Write(arrayName);
             base.Writer.Write(".Length");
         }
         else
         {
             base.Writer.Write("((");
             base.Writer.Write(typeof(ICollection).FullName);
             base.Writer.Write(")");
             base.Writer.Write(arrayName);
             base.Writer.Write(").Count");
         }
         base.Writer.Write("; i");
         base.Writer.Write(arrayName);
         base.Writer.WriteLine("++) {");
         IndentedWriter writer2 = base.Writer;
         writer2.Indent++;
         int num = elements.Length + ((text == null) ? 0 : 1);
         if (num > 1)
         {
             string typeName = arrayElementTypeDesc.CSharpName;
             this.WriteLocalDecl(typeName, arrayName + "i", base.RaCodeGen.GetStringForArrayMember(arrayName, "i" + arrayName, arrayTypeDesc), arrayElementTypeDesc.UseReflection);
             if (choice != null)
             {
                 string str3 = choice.Mapping.TypeDesc.CSharpName;
                 this.WriteLocalDecl(str3, choiceName + "i", base.RaCodeGen.GetStringForArrayMember(choiceName, "i" + arrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.UseReflection);
             }
             this.WriteElements(arrayName + "i", choiceName + "i", elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
         }
         else
         {
             this.WriteElements(base.RaCodeGen.GetStringForArrayMember(arrayName, "i" + arrayName, arrayTypeDesc), elements, text, choice, arrayName + "a", true, arrayElementTypeDesc.IsNullable);
         }
     }
     IndentedWriter writer = base.Writer;
     writer.Indent--;
     base.Writer.WriteLine("}");
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:XmlSerializationWriterCodeGen.cs


示例13: WriteElement

        void WriteElement(string source, string arrayName, string choiceSource, ElementAccessor element, ChoiceIdentifierAccessor choice, string checkSpecified, bool checkForNull, bool readOnly, int fixupIndex, int elementIndex) {
            if (checkSpecified != null && checkSpecified.Length > 0) {
                ILGenSet(checkSpecified, true);
            }

            if (element.Mapping is ArrayMapping) {
                WriteArray(source, arrayName, (ArrayMapping)element.Mapping, readOnly, element.IsNullable, fixupIndex, elementIndex);
            }
            else if (element.Mapping is NullableMapping) {
                string methodName = ReferenceMapping(element.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, element.Mapping.TypeDesc.Name));
#endif
                WriteSourceBegin(source);
                ilg.Ldarg(0);
                ilg.Ldc(true);
                MethodBuilder methodBuilder = EnsureMethodBuilder(typeBuilder,
                    methodName,
                    CodeGenerator.PrivateMethodAttributes,
                    // See WriteNullableMethod for different return type logic
                    element.Mapping.TypeDesc.Type,
                    new Type[] { typeof(Boolean) }
                    );
                ilg.Call(methodBuilder);
                WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
            }
            else if (element.Mapping is PrimitiveMapping) {
                bool doEndIf = false;
                if (element.IsNullable) {
                    MethodInfo XmlSerializationReader_ReadNull = typeof(XmlSerializationReader).GetMethod(
                         "ReadNull",
                         CodeGenerator.InstanceBindingFlags,
                         null,
                         CodeGenerator.EmptyTypeArray,
                         null
                         );
                    ilg.Ldarg(0);
                    ilg.Call(XmlSerializationReader_ReadNull);
                    ilg.If();
                    WriteSourceBegin(source);
                    if (element.Mapping.TypeDesc.IsValueType) {
                        throw CodeGenerator.NotSupported("No such condition.  PrimitiveMapping && IsNullable = String, XmlQualifiedName and never IsValueType");
                    }
                    else {
                        ilg.Load(null);
                    }
                    WriteSourceEnd(source, element.Mapping.TypeDesc.Type);
                    ilg.Else();
                    doEndIf = true;
                }
                if (element.Default != null && element.Default != DBNull.Value && element.Mapping.TypeDesc.IsValueType) {
                    MethodInfo XmlSerializationReader_get_Reader = typeof(XmlSerializationReader).GetMethod(
                        "get_Reader",
                        CodeGenerator.InstanceBindingFlags,
                        null,
                        CodeGenerator.EmptyTypeArray,
                        null
                        );
                    MethodInfo XmlReader_get_IsEmptyElement = typeof(XmlReader).GetMethod(
                        "get_IsEmptyElement",
                        CodeGenerator.InstanceBindingFlags,
                        null,
                        CodeGenerator.EmptyTypeArray,
                        null
                        );
                    ilg.Ldarg(0);
                    ilg.Call(XmlSerializationReader_get_Reader);
                    ilg.Call(XmlReader_get_IsEmptyElement);
                    ilg.If();
                    MethodInfo XmlReader_Skip = typeof(XmlReader).GetMethod(
                        "Skip",
                        CodeGenerator.InstanceBindingFlags,
                        null,
                        CodeGenerator.EmptyTypeArray,
                        null
                        );
                    ilg.Ldarg(0);
                    ilg.Call(XmlSerializationReader_get_Reader);
                    ilg.Call(XmlReader_Skip);
                    ilg.Else();
                    doEndIf = true;
                }
                else {
                }

                WriteSourceBegin(source);
                if (element.Mapping.TypeDesc == QnameTypeDesc) {
                    MethodInfo XmlSerializationReader_ReadElementQualifiedName = typeof(XmlSerializationReader).GetMethod(
                           "ReadElementQualifiedName",
                           CodeGenerator.InstanceBindingFlags,
                           null,
                           CodeGenerator.EmptyTypeArray,
                           null
                           );
                    ilg.Ldarg(0);
                    ilg.Call(XmlSerializationReader_ReadElementQualifiedName);
                }
                else {
                    string readFunc;
//.........这里部分代码省略.........
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:XmlSerializationReaderILGen.cs


示例14: WriteArrayItems


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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