本文整理汇总了C#中System.Xml.Serialization.ChoiceIdentifierAccessor类的典型用法代码示例。如果您正苦于以下问题:C# ChoiceIdentifierAccessor类的具体用法?C# ChoiceIdentifierAccessor怎么用?C# ChoiceIdentifierAccessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ChoiceIdentifierAccessor类属于System.Xml.Serialization命名空间,在下文中一共展示了ChoiceIdentifierAccessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
//.........这里部分代码省略.........
示例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);
}
示例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("}");
}
示例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);
}
}
}
示例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(");");
}
示例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);
}
示例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("}");
}
示例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);
//.........这里部分代码省略.........
示例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("}");
}
示例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;
//.........这里部分代码省略.........
示例14: WriteArrayItems
void WriteArrayItems(ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc arrayTypeDesc, string arrayName, string choiceName)
{
TypeDesc arrayElementTypeDesc = arrayTypeDesc.ArrayElementTypeDesc;
// The logic here is that
// 1) Try to get the public "GetEnumerator" method. If the method exists, then use this method.
// 2) If there's no public method exist, check if the type implemented IEnumerable<T>. If so, call the explicit method
// 3) Otherwise, call the IEnumerable.GetEnumerator method
if (arrayTypeDesc.IsEnumerable)
{
LocalBuilder eLoc = ilg.DeclareLocal(typeof(IEnumerator), "e");
MethodInfo getEnumeratorMethod = arrayTypeDesc.Type.GetMethod(
"GetEnumerator",
CodeGenerator.InstancePublicBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null);
if (getEnumeratorMethod != null && typeof(IEnumerator).IsAssignableFrom(getEnumeratorMethod.ReturnType))
{
ilg.LoadAddress(ilg.GetVariable(arrayName));
}
else
{
ilg.Load(ilg.GetVariable(arrayName));
Type typeIEnumerable = arrayTypeDesc.IsGenericInterface ? typeof(IEnumerable<>).MakeGenericType(arrayElementTypeDesc.Type) : typeof(IEnumerable);
getEnumeratorMethod = typeIEnumerable.GetMethod(
"GetEnumerator",
CodeGenerator.InstanceBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null);
ilg.ConvertValue(arrayTypeDesc.Type, typeIEnumerable);
}
ilg.Call(getEnumeratorMethod);
ilg.ConvertValue(getEnumeratorMethod.ReturnType, typeof(IEnumerator));
ilg.Stloc(eLoc);
ilg.Ldloc(eLoc);
ilg.Load(null);
ilg.If(Cmp.NotEqualTo);
ilg.WhileBegin();
string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
WriteLocalDecl(arrayNamePlusI, "e.Current", arrayElementTypeDesc.Type);
WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, true);
ilg.WhileBeginCondition(); // while (e.MoveNext())
MethodInfo IEnumerator_MoveNext = typeof(IEnumerator).GetMethod(
"MoveNext",
CodeGenerator.InstanceBindingFlags,
null,
CodeGenerator.EmptyTypeArray,
null
);
ilg.Ldloc(eLoc);
ilg.Call(IEnumerator_MoveNext);
ilg.WhileEndCondition();
ilg.WhileEnd();
ilg.EndIf(); // if (e != null)
}
else {
// Filter out type specific for index (code match reusing local).
string iPlusArrayName = "i" + (arrayName).Replace(arrayTypeDesc.Name, "");
string arrayNamePlusA = (arrayName).Replace(arrayTypeDesc.Name, "") + "a" + arrayElementTypeDesc.Name;
string arrayNamePlusI = (arrayName).Replace(arrayTypeDesc.Name, "") + "i" + arrayElementTypeDesc.Name;
LocalBuilder localI = ilg.DeclareOrGetLocal(typeof(Int32), iPlusArrayName);
ilg.For(localI, 0, ilg.GetLocal(arrayName));
int count = elements.Length + (text == null ? 0 : 1);
if (count > 1) {
WriteLocalDecl(arrayNamePlusI, RaCodeGen.GetStringForArrayMember(arrayName, iPlusArrayName, arrayTypeDesc), arrayElementTypeDesc.Type);
if (choice != null) {
WriteLocalDecl(choiceName + "i", RaCodeGen.GetStringForArrayMember(choiceName, iPlusArrayName, choice.Mapping.TypeDesc), choice.Mapping.TypeDesc.Type);
}
WriteElements(new SourceInfo(arrayNamePlusI, null, null, arrayElementTypeDesc.Type, ilg), choiceName + "i", elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable);
}
else {
WriteElements(new SourceInfo(RaCodeGen.GetStringForArrayMember(arrayName, iPlusArrayName, arrayTypeDesc), null, null, arrayElementTypeDesc.Type, ilg), null, elements, text, choice, arrayNamePlusA, true, arrayElementTypeDesc.IsNullable);
}
ilg.EndFor();
}
}
示例15: WriteMember
private void WriteMember(object o, object choiceSource, ElementAccessor[] elements, TextAccessor text, ChoiceIdentifierAccessor choice, TypeDesc memberTypeDesc, bool writeAccessors, XmlMapping parentMapping = null)
{
if (memberTypeDesc.IsArrayLike &&
!(elements.Length == 1 && elements[0].Mapping is ArrayMapping))
{
WriteArray(o, choiceSource, elements, text, choice, memberTypeDesc);
}
else
{
WriteElements(o, choiceSource, elements, text, choice, "a", writeAccessors, memberTypeDesc.IsNullable, parentMapping);
}
}