本文整理汇总了C#中System.Xml.Serialization.ElementAccessor.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# ElementAccessor.Clone方法的具体用法?C# ElementAccessor.Clone怎么用?C# ElementAccessor.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.ElementAccessor
的用法示例。
在下文中一共展示了ElementAccessor.Clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteElement
void WriteElement(string source, ElementAccessor element, string arrayName, bool writeAccessor) {
string name = writeAccessor ? element.Name : element.Mapping.TypeName;
string ns = element.Any && element.Name.Length == 0 ? null : (element.Form == XmlSchemaForm.Qualified ? (writeAccessor ? element.Namespace : element.Mapping.Namespace) : "");
if (element.Mapping is NullableMapping) {
Writer.Write("if (");
Writer.Write(source);
Writer.WriteLine(" != null) {");
Writer.Indent++;
string fullTypeName = element.Mapping.TypeDesc.BaseTypeDesc.CSharpName;
string castedSource = source;
if (!element.Mapping.TypeDesc.BaseTypeDesc.UseReflection)
castedSource = "(("+fullTypeName+")"+ source+")";
ElementAccessor e = element.Clone();
e.Mapping = ((NullableMapping)element.Mapping).BaseMapping;
WriteElement(e.Any ? source : castedSource, e, arrayName, writeAccessor);
Writer.Indent--;
Writer.WriteLine("}");
if (element.IsNullable) {
Writer.WriteLine("else {");
Writer.Indent++;
WriteLiteralNullTag(element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
Writer.Indent--;
Writer.WriteLine("}");
}
}
else if (element.Mapping is ArrayMapping) {
ArrayMapping mapping = (ArrayMapping)element.Mapping;
if (mapping.IsSoap) {
Writer.Write("WritePotentiallyReferencingElement(");
WriteQuotedCSharpString(name);
Writer.Write(", ");
WriteQuotedCSharpString(ns);
Writer.Write(", ");
Writer.Write(source);
if (!writeAccessor) {
Writer.Write(", ");
Writer.Write(RaCodeGen.GetStringForTypeof(mapping.TypeDesc.CSharpName, mapping.TypeDesc.UseReflection));
Writer.Write(", true, ");
}
else {
Writer.Write(", null, false, ");
}
WriteValue(element.IsNullable);
Writer.WriteLine(");");
}
else if (element.IsUnbounded) {
TypeDesc td = mapping.TypeDesc.CreateArrayTypeDesc();
string fullTypeName = td.CSharpName;
string elementArrayName = "el" + arrayName;
string arrayIndex = "c" + elementArrayName;
Writer.WriteLine("{");
Writer.Indent++;
WriteArrayLocalDecl(fullTypeName, elementArrayName, source, mapping.TypeDesc);
if (element.IsNullable) {
WriteNullCheckBegin(elementArrayName, element);
}
else {
if (mapping.TypeDesc.IsNullable) {
Writer.Write("if (");
Writer.Write(elementArrayName);
Writer.Write(" != null)");
}
Writer.WriteLine("{");
Writer.Indent++;
}
Writer.Write("for (int ");
Writer.Write(arrayIndex);
Writer.Write(" = 0; ");
Writer.Write(arrayIndex);
Writer.Write(" < ");
if (td.IsArray) {
Writer.Write(elementArrayName);
Writer.Write(".Length");
}
else {
Writer.Write("((");
Writer.Write(typeof(ICollection).FullName);
Writer.Write(")");
Writer.Write(elementArrayName);
Writer.Write(").Count");
}
Writer.Write("; ");
Writer.Write(arrayIndex);
Writer.WriteLine("++) {");
Writer.Indent++;
element.IsUnbounded = false;
WriteElement(elementArrayName + "[" + arrayIndex + "]", element, arrayName, writeAccessor);
element.IsUnbounded = true;
Writer.Indent--;
Writer.WriteLine("}");
Writer.Indent--;
Writer.WriteLine("}");
Writer.Indent--;
Writer.WriteLine("}");
}
//.........这里部分代码省略.........
示例2: WriteElement
private void WriteElement(SourceInfo source, ElementAccessor element, string arrayName, bool writeAccessor)
{
string name = writeAccessor ? element.Name : element.Mapping.TypeName;
string ns = element.Any && element.Name.Length == 0 ? null : (element.Form == XmlSchemaForm.Qualified ? (writeAccessor ? element.Namespace : element.Mapping.Namespace) : "");
if (element.Mapping is NullableMapping)
{
if (source.Type == element.Mapping.TypeDesc.Type)
{
MethodInfo Nullable_get_HasValue = element.Mapping.TypeDesc.Type.GetMethod(
"get_HasValue",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
source.LoadAddress(element.Mapping.TypeDesc.Type);
ilg.Call(Nullable_get_HasValue);
}
else
{
source.Load(null);
ilg.Load(null);
ilg.Cne();
}
ilg.If();
string fullTypeName = element.Mapping.TypeDesc.BaseTypeDesc.CSharpName;
SourceInfo castedSource = source.CastTo(element.Mapping.TypeDesc.BaseTypeDesc);
ElementAccessor e = element.Clone();
e.Mapping = ((NullableMapping)element.Mapping).BaseMapping;
WriteElement(e.Any ? source : castedSource, e, arrayName, writeAccessor);
if (element.IsNullable)
{
ilg.Else();
WriteLiteralNullTag(element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
}
ilg.EndIf();
}
else if (element.Mapping is ArrayMapping)
{
ArrayMapping mapping = (ArrayMapping)element.Mapping;
if (element.IsUnbounded)
{
throw Globals.NotSupported("Unreachable: IsUnbounded is never set true!");
}
else
{
ilg.EnterScope();
string fullTypeName = mapping.TypeDesc.CSharpName;
WriteArrayLocalDecl(fullTypeName, arrayName, source, mapping.TypeDesc);
if (element.IsNullable)
{
WriteNullCheckBegin(arrayName, element);
}
else
{
if (mapping.TypeDesc.IsNullable)
{
ilg.Ldloc(ilg.GetLocal(arrayName));
ilg.Load(null);
ilg.If(Cmp.NotEqualTo);
}
}
WriteStartElement(name, ns, false);
WriteArrayItems(mapping.ElementsSortedByDerivation, null, null, mapping.TypeDesc, arrayName, null);
WriteEndElement();
if (element.IsNullable)
{
ilg.EndIf();
}
else
{
if (mapping.TypeDesc.IsNullable)
{
ilg.EndIf();
}
}
ilg.ExitScope();
}
}
else if (element.Mapping is EnumMapping)
{
WritePrimitive("WriteElementString", name, ns, element.Default, source, element.Mapping, false, true, element.IsNullable);
}
else if (element.Mapping is PrimitiveMapping)
{
PrimitiveMapping mapping = (PrimitiveMapping)element.Mapping;
if (mapping.TypeDesc == QnameTypeDesc)
WriteQualifiedNameElement(name, ns, element.Default, source, element.IsNullable, mapping);
else
{
string suffixRaw = mapping.TypeDesc.XmlEncodingNotRequired ? "Raw" : "";
WritePrimitive(element.IsNullable ? ("WriteNullableStringLiteral" + suffixRaw) : ("WriteElementString" + suffixRaw),
name, ns, element.Default, source, mapping, false, true, element.IsNullable);
}
}
else if (element.Mapping is StructMapping)
{
StructMapping mapping = (StructMapping)element.Mapping;
string methodName = ReferenceMapping(mapping);
#if DEBUG
//.........这里部分代码省略.........
示例3: WriteElement
private void WriteElement(object o, ElementAccessor element, string arrayName, bool writeAccessor, XmlMapping parentMapping = null)
{
string name = writeAccessor ? element.Name : element.Mapping.TypeName;
string ns = element.Any && element.Name.Length == 0 ? null : (element.Form == XmlSchemaForm.Qualified ? (writeAccessor ? element.Namespace : element.Mapping.Namespace) : "");
if (element.Mapping is NullableMapping)
{
if (o != null)
{
ElementAccessor e = element.Clone();
e.Mapping = ((NullableMapping)element.Mapping).BaseMapping;
WriteElement(o, e, arrayName, writeAccessor);
}
else if (element.IsNullable)
{
WriteNullTagLiteral(element.Name, ns);
}
}
else if (element.Mapping is ArrayMapping)
{
var mapping = (ArrayMapping)element.Mapping;
if (mapping.IsSoap)
{
throw new PlatformNotSupportedException();
}
if (element.IsNullable && o == null)
{
WriteNullTagLiteral(element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
}
else
{
if (element.IsUnbounded)
{
TypeDesc arrayTypeDesc = mapping.TypeDesc.CreateArrayTypeDesc();
var enumerable = (IEnumerable)o;
foreach (var e in enumerable)
{
element.IsUnbounded = false;
WriteElement(e, element, arrayName, writeAccessor);
element.IsUnbounded = true;
}
}
else
{
if (o != null)
{
WriteStartElement(name, ns, false);
WriteArrayItems(mapping.ElementsSortedByDerivation, null, null, mapping.TypeDesc, o);
WriteEndElement();
}
}
}
}
else if (element.Mapping is EnumMapping)
{
if (element.Mapping.IsSoap)
{
throw new PlatformNotSupportedException();
}
else
{
WritePrimitive(WritePrimitiveMethodRequirement.WriteElementString, name, ns, element.Default, o, element.Mapping, false, true, element.IsNullable);
}
}
else if (element.Mapping is PrimitiveMapping)
{
PrimitiveMapping mapping = (PrimitiveMapping)element.Mapping;
if (mapping.TypeDesc == QnameTypeDesc)
{
WriteQualifiedNameElement(name, ns, element.Default, (XmlQualifiedName)o, element.IsNullable, mapping.IsSoap, mapping);
}
else
{
if (mapping.IsSoap)
{
throw new PlatformNotSupportedException();
}
WritePrimitiveMethodRequirement suffixRaw = mapping.TypeDesc.XmlEncodingNotRequired ? WritePrimitiveMethodRequirement.Raw : WritePrimitiveMethodRequirement.None;
WritePrimitive(element.IsNullable
? WritePrimitiveMethodRequirement.WriteNullableStringLiteral | suffixRaw
: WritePrimitiveMethodRequirement.WriteElementString | suffixRaw,
name, ns, element.Default, o, mapping, mapping.IsSoap, true, element.IsNullable);
}
}
else if (element.Mapping is StructMapping)
{
var mapping = (StructMapping)element.Mapping;
if (mapping.IsSoap)
{
throw new PlatformNotSupportedException();
}
WriteStructMethod(mapping, name, ns, o, mapping.TypeDesc.IsNullable, needType: false, parentMapping: parentMapping);
}
else if (element.Mapping is SpecialMapping)
{
if (element.Mapping is SerializableMapping)
//.........这里部分代码省略.........
示例4: WriteElement
private void WriteElement(string source, ElementAccessor element, string arrayName, bool writeAccessor)
{
string str = writeAccessor ? element.Name : element.Mapping.TypeName;
string str2 = (element.Any && (element.Name.Length == 0)) ? null : ((element.Form == XmlSchemaForm.Qualified) ? (writeAccessor ? element.Namespace : element.Mapping.Namespace) : "");
if (element.Mapping is NullableMapping)
{
base.Writer.Write("if (");
base.Writer.Write(source);
base.Writer.WriteLine(" != null) {");
IndentedWriter writer = base.Writer;
writer.Indent++;
string cSharpName = element.Mapping.TypeDesc.BaseTypeDesc.CSharpName;
string str4 = source;
if (!element.Mapping.TypeDesc.BaseTypeDesc.UseReflection)
{
str4 = "((" + cSharpName + ")" + source + ")";
}
ElementAccessor accessor = element.Clone();
accessor.Mapping = ((NullableMapping) element.Mapping).BaseMapping;
this.WriteElement(accessor.Any ? source : str4, accessor, arrayName, writeAccessor);
IndentedWriter writer2 = base.Writer;
writer2.Indent--;
base.Writer.WriteLine("}");
if (element.IsNullable)
{
base.Writer.WriteLine("else {");
IndentedWriter writer3 = base.Writer;
writer3.Indent++;
this.WriteLiteralNullTag(element.Name, (element.Form == XmlSchemaForm.Qualified) ? element.Namespace : "");
IndentedWriter writer4 = base.Writer;
writer4.Indent--;
base.Writer.WriteLine("}");
}
}
else if (element.Mapping is ArrayMapping)
{
ArrayMapping mapping = (ArrayMapping) element.Mapping;
if (mapping.IsSoap)
{
base.Writer.Write("WritePotentiallyReferencingElement(");
base.WriteQuotedCSharpString(str);
base.Writer.Write(", ");
base.WriteQuotedCSharpString(str2);
base.Writer.Write(", ");
base.Writer.Write(source);
if (!writeAccessor)
{
base.Writer.Write(", ");
base.Writer.Write(base.RaCodeGen.GetStringForTypeof(mapping.TypeDesc.CSharpName, mapping.TypeDesc.UseReflection));
base.Writer.Write(", true, ");
}
else
{
base.Writer.Write(", null, false, ");
}
this.WriteValue(element.IsNullable);
base.Writer.WriteLine(");");
}
else if (element.IsUnbounded)
{
TypeDesc desc = mapping.TypeDesc.CreateArrayTypeDesc();
string typeName = desc.CSharpName;
string variableName = "el" + arrayName;
string s = "c" + variableName;
base.Writer.WriteLine("{");
IndentedWriter writer5 = base.Writer;
writer5.Indent++;
this.WriteArrayLocalDecl(typeName, variableName, source, mapping.TypeDesc);
if (element.IsNullable)
{
this.WriteNullCheckBegin(variableName, element);
}
else
{
if (mapping.TypeDesc.IsNullable)
{
base.Writer.Write("if (");
base.Writer.Write(variableName);
base.Writer.Write(" != null)");
}
base.Writer.WriteLine("{");
IndentedWriter writer6 = base.Writer;
writer6.Indent++;
}
base.Writer.Write("for (int ");
base.Writer.Write(s);
base.Writer.Write(" = 0; ");
base.Writer.Write(s);
base.Writer.Write(" < ");
if (desc.IsArray)
{
base.Writer.Write(variableName);
base.Writer.Write(".Length");
}
else
{
base.Writer.Write("((");
base.Writer.Write(typeof(ICollection).FullName);
base.Writer.Write(")");
base.Writer.Write(variableName);
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:XmlSerializationWriterCodeGen.cs