本文整理汇总了C#中System.Xml.Serialization.SourceInfo.Load方法的典型用法代码示例。如果您正苦于以下问题:C# SourceInfo.Load方法的具体用法?C# SourceInfo.Load怎么用?C# SourceInfo.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.SourceInfo
的用法示例。
在下文中一共展示了SourceInfo.Load方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ILGenLoad
internal void ILGenLoad(string source, Type type)
{
if (source.StartsWith("[email protected]", StringComparison.Ordinal))
{
System.Diagnostics.Debug.Assert(memberInfos.ContainsKey(source.Substring(3)));
MemberInfo memInfo = memberInfos[source.Substring(3)];
ilg.LoadMember(ilg.GetVariable("o"), memInfo);
if (type != null)
{
Type memType = (memInfo is FieldInfo) ? ((FieldInfo)memInfo).FieldType : ((PropertyInfo)memInfo).PropertyType;
ilg.ConvertValue(memType, type);
}
}
else
{
SourceInfo info = new SourceInfo(source, null, null, null, ilg);
info.Load(type);
}
}
示例2: WriteArrayLocalDecl
internal void WriteArrayLocalDecl(string typeName, string variableName, SourceInfo initValue, TypeDesc arrayTypeDesc)
{
Debug.Assert(typeName == arrayTypeDesc.CSharpName || typeName == arrayTypeDesc.CSharpName + "[]");
Type localType = (typeName == arrayTypeDesc.CSharpName) ? arrayTypeDesc.Type : arrayTypeDesc.Type.MakeArrayType();
// This may need reused varialble to get code compat?
LocalBuilder local = initValue.ILG.DeclareOrGetLocal(localType, variableName);
if (initValue != null)
{
initValue.Load(local.LocalType);
initValue.ILG.Stloc(local);
}
}
示例3: WriteQualifiedNameElement
private void WriteQualifiedNameElement(string name, string ns, object defaultValue, SourceInfo source, bool nullable, TypeMapping mapping)
{
bool hasDefault = defaultValue != null && !Globals.IsDBNullValue(defaultValue);
if (hasDefault)
{
throw Globals.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
}
List<Type> argTypes = new List<Type>();
ilg.Ldarg(0);
ilg.Ldstr(GetCSharpString(name));
argTypes.Add(typeof(string));
if (ns != null)
{
ilg.Ldstr(GetCSharpString(ns));
argTypes.Add(typeof(string));
}
source.Load(mapping.TypeDesc.Type);
argTypes.Add(mapping.TypeDesc.Type);
MethodInfo XmlSerializationWriter_WriteXXX = typeof(XmlSerializationWriter).GetMethod(
nullable ? ("WriteNullableQualifiedNameLiteral") : "WriteElementQualifiedName",
CodeGenerator.InstanceBindingFlags,
argTypes.ToArray()
);
ilg.Call(XmlSerializationWriter_WriteXXX);
if (hasDefault)
{
throw Globals.NotSupported("XmlQualifiedName DefaultValue not supported. Fail in WriteValue()");
}
}
示例4: WriteLocalDecl
internal void WriteLocalDecl(string variableName, SourceInfo initValue)
{
Type localType = initValue.Type;
LocalBuilder localA = initValue.ILG.DeclareOrGetLocal(localType, variableName);
if (initValue.Source != null)
{
if (initValue == "null")
{
initValue.ILG.Load(null);
}
else
{
if (initValue.Arg.StartsWith("[email protected]", StringComparison.Ordinal))
{
Debug.Assert(initValue.MemberInfo != null);
Debug.Assert(initValue.MemberInfo.Name == initValue.Arg.Substring(3));
initValue.ILG.LoadMember(initValue.ILG.GetLocal("o"), initValue.MemberInfo);
}
else if (initValue.Source.EndsWith("]", StringComparison.Ordinal))
{
initValue.Load(initValue.Type);
}
else if (initValue.Source == "fixup.Source" || initValue.Source == "e.Current")
{
String[] vars = initValue.Source.Split('.');
object fixup = initValue.ILG.GetVariable(vars[0]);
PropertyInfo propInfo = initValue.ILG.GetVariableType(fixup).GetProperty(vars[1]);
initValue.ILG.LoadMember(fixup, propInfo);
initValue.ILG.ConvertValue(propInfo.PropertyType, localA.LocalType);
}
else
{
object sVar = initValue.ILG.GetVariable(initValue.Arg);
initValue.ILG.Load(sVar);
initValue.ILG.ConvertValue(initValue.ILG.GetVariableType(sVar), localA.LocalType);
}
}
initValue.ILG.Stloc(localA);
}
}
示例5: WriteInstanceOf
internal void WriteInstanceOf(SourceInfo source, Type type, CodeGenerator ilg)
{
{
source.Load(typeof(object));
ilg.IsInst(type);
ilg.Load(null);
ilg.Cne();
return;
}
}
示例6: WriteCheckDefault
private void WriteCheckDefault(SourceInfo source, object value, bool isNullable)
{
if (value is string && ((string)value).Length == 0)
{
// special case for string compare
Label labelEnd = ilg.DefineLabel();
Label labelFalse = ilg.DefineLabel();
Label labelTrue = ilg.DefineLabel();
source.Load(typeof(string));
if (isNullable)
// check == null with false
ilg.Brfalse(labelTrue);
else
//check != null with false
ilg.Brfalse(labelFalse);
MethodInfo String_get_Length = typeof(string).GetMethod(
"get_Length",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
source.Load(typeof(string));
ilg.Call(String_get_Length);
ilg.Ldc(0);
ilg.Cne();
ilg.Br(labelEnd);
if (isNullable)
{
ilg.MarkLabel(labelTrue);
ilg.Ldc(true);
}
else
{
ilg.MarkLabel(labelFalse);
ilg.Ldc(false);
}
ilg.MarkLabel(labelEnd);
ilg.If();
}
else
{
if (value == null)
{
source.Load(typeof(object));
ilg.Load(null);
ilg.Cne();
}
else if (value.GetType().GetTypeInfo().IsPrimitive)
{
source.Load(null);
ilg.Ldc(Convert.ChangeType(value, source.Type, CultureInfo.InvariantCulture));
ilg.Cne();
}
else
{
Type valueType = value.GetType();
source.Load(valueType);
ilg.Ldc(value is string ? GetCSharpString((string)value) : value);
MethodInfo op_Inequality = valueType.GetMethod(
"op_Inequality",
CodeGenerator.StaticBindingFlags,
new Type[] { valueType, valueType }
);
if (op_Inequality != null)
ilg.Call(op_Inequality);
else
ilg.Cne();
}
ilg.If();
}
}
示例7: WriteChoiceTypeCheck
private void WriteChoiceTypeCheck(SourceInfo source, string fullTypeName, ChoiceIdentifierAccessor choice, string enumName, TypeDesc typeDesc)
{
Label labelFalse = ilg.DefineLabel();
Label labelEnd = ilg.DefineLabel();
source.Load(typeof(object));
ilg.Load(null);
ilg.Beq(labelFalse);
WriteInstanceOf(source, typeDesc.Type);
// Negative
ilg.Ldc(false);
ilg.Ceq();
ilg.Br(labelEnd);
ilg.MarkLabel(labelFalse);
ilg.Ldc(false);
ilg.MarkLabel(labelEnd);
ilg.If();
MethodInfo XmlSerializationWriter_CreateMismatchChoiceException = typeof(XmlSerializationWriter).GetMethod(
"CreateMismatchChoiceException",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(String), typeof(String), typeof(String) }
);
ilg.Ldarg(0);
ilg.Ldstr(GetCSharpString(typeDesc.FullName));
ilg.Ldstr(GetCSharpString(choice.MemberName));
ilg.Ldstr(GetCSharpString(enumName));
ilg.Call(XmlSerializationWriter_CreateMismatchChoiceException);
ilg.Throw();
ilg.EndIf();
}
示例8: WritePrimitive
private void WritePrimitive(string method, string name, string ns, object defaultValue, SourceInfo source, TypeMapping mapping, bool writeXsiType, bool isElement, bool isNullable)
{
TypeDesc typeDesc = mapping.TypeDesc;
bool hasDefault = defaultValue != null && !Globals.IsDBNullValue(defaultValue) && mapping.TypeDesc.HasDefaultSupport;
if (hasDefault)
{
if (mapping is EnumMapping)
{
#if DEBUG
// use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
if (defaultValue.GetType() != typeof(string)) throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, name + " has invalid default type " + defaultValue.GetType().Name));
#endif
source.Load(mapping.TypeDesc.Type);
string enumDefaultValue = null;
if (((EnumMapping)mapping).IsFlags)
{
string[] values = ((string)defaultValue).Split(null);
for (int i = 0; i < values.Length; i++)
{
if (values[i] == null || values[i].Length == 0)
continue;
if (i > 0)
enumDefaultValue += ", ";
enumDefaultValue += values[i];
}
}
else
{
enumDefaultValue = (string)defaultValue;
}
ilg.Ldc(Enum.Parse(mapping.TypeDesc.Type, enumDefaultValue, false));
ilg.If(Cmp.NotEqualTo); // " != "
}
else
{
WriteCheckDefault(source, defaultValue, isNullable);
}
}
List<Type> argTypes = new List<Type>();
ilg.Ldarg(0);
argTypes.Add(typeof(String));
ilg.Ldstr(GetCSharpString(name));
if (ns != null)
{
argTypes.Add(typeof(String));
ilg.Ldstr(GetCSharpString(ns));
}
Type argType;
if (mapping is EnumMapping)
{
WriteEnumValue((EnumMapping)mapping, source, out argType);
argTypes.Add(argType);
}
else
{
WritePrimitiveValue(typeDesc, source, out argType);
argTypes.Add(argType);
}
if (writeXsiType)
{
argTypes.Add(typeof(XmlQualifiedName));
ConstructorInfo XmlQualifiedName_ctor = typeof(XmlQualifiedName).GetConstructor(
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(String), typeof(String) }
);
ilg.Ldstr(GetCSharpString(mapping.TypeName));
ilg.Ldstr(GetCSharpString(mapping.Namespace));
ilg.New(XmlQualifiedName_ctor);
}
MethodInfo XmlSerializationWriter_method = typeof(XmlSerializationWriter).GetMethod(
method,
CodeGenerator.InstanceBindingFlags,
argTypes.ToArray()
);
ilg.Call(XmlSerializationWriter_method);
if (hasDefault)
{
ilg.EndIf();
}
}
示例9: WriteElementCall
private void WriteElementCall(string func, Type cast, SourceInfo source, string name, string ns, bool isNullable, bool isAny)
{
MethodInfo XmlSerializationWriter_func = typeof(XmlSerializationWriter).GetMethod(
func,
CodeGenerator.InstanceBindingFlags,
new Type[] { cast, typeof(String), typeof(String), typeof(Boolean), typeof(Boolean) }
);
ilg.Ldarg(0);
source.Load(cast);
ilg.Ldstr(GetCSharpString(name));
ilg.Ldstr(GetCSharpString(ns));
ilg.Ldc(isNullable);
ilg.Ldc(isAny);
ilg.Call(XmlSerializationWriter_func);
}
示例10: 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
//.........这里部分代码省略.........
示例11: WriteText
private void WriteText(SourceInfo source, TextAccessor text)
{
if (text.Mapping is PrimitiveMapping)
{
PrimitiveMapping mapping = (PrimitiveMapping)text.Mapping;
Type argType;
ilg.Ldarg(0);
if (text.Mapping is EnumMapping)
{
WriteEnumValue((EnumMapping)text.Mapping, source, out argType);
}
else
{
WritePrimitiveValue(mapping.TypeDesc, source, out argType);
}
MethodInfo XmlSerializationWriter_WriteValue = typeof(XmlSerializationWriter).GetMethod(
"WriteValue",
CodeGenerator.InstanceBindingFlags,
new Type[] { argType }
);
ilg.Call(XmlSerializationWriter_WriteValue);
}
else if (text.Mapping is SpecialMapping)
{
SpecialMapping mapping = (SpecialMapping)text.Mapping;
switch (mapping.TypeDesc.Kind)
{
case TypeKind.Node:
MethodInfo WriteTo = source.Type.GetMethod(
"WriteTo",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(XmlWriter) }
);
MethodInfo XmlSerializationWriter_get_Writer = typeof(XmlSerializationWriter).GetMethod(
"get_Writer",
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
source.Load(source.Type);
ilg.Ldarg(0);
ilg.Call(XmlSerializationWriter_get_Writer);
ilg.Call(WriteTo);
break;
default:
throw new InvalidOperationException(SR.XmlInternalError);
}
}
}
示例12: WriteElements
private void WriteElements(SourceInfo 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.IsOptionalValue)
source = source.CastTo(td);
WriteElement(source, elements[0], arrayName, writeAccessors);
}
else
{
bool doEndIf = false;
if (isNullable && choice == null)
{
source.Load(typeof(object));
ilg.Load(null);
ilg.If(Cmp.NotEqualTo);
doEndIf = true;
}
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)
{
string fullTypeName = element.Mapping.TypeDesc.CSharpName;
object enumValue;
string enumFullName = enumTypeName + "[email protected]" + FindChoiceEnumValue(element, (EnumMapping)choice.Mapping, out enumValue);
if (wroteFirstIf) ilg.InitElseIf();
else { wroteFirstIf = true; ilg.InitIf(); }
ILGenLoad(enumSource, choice == null ? null : choice.Mapping.TypeDesc.Type);
ilg.Load(enumValue);
ilg.Ceq();
if (isNullable && !element.IsNullable)
{
Label labelFalse = ilg.DefineLabel();
Label labelEnd = ilg.DefineLabel();
ilg.Brfalse(labelFalse);
source.Load(typeof(object));
ilg.Load(null);
ilg.Cne();
ilg.Br_S(labelEnd);
ilg.MarkLabel(labelFalse);
ilg.Ldc(false);
ilg.MarkLabel(labelEnd);
}
ilg.AndIf();
WriteChoiceTypeCheck(source, fullTypeName, choice, enumFullName, element.Mapping.TypeDesc);
SourceInfo castedSource = source;
castedSource = source.CastTo(element.Mapping.TypeDesc);
WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
}
else
{
TypeDesc td = element.IsUnbounded ? element.Mapping.TypeDesc.CreateArrayTypeDesc() : element.Mapping.TypeDesc;
string fullTypeName = td.CSharpName;
if (wroteFirstIf) ilg.InitElseIf();
else { wroteFirstIf = true; ilg.InitIf(); }
WriteInstanceOf(source, td.Type);
// WriteInstanceOf leave bool on the stack
ilg.AndIf();
SourceInfo castedSource = source;
castedSource = source.CastTo(td);
WriteElement(element.Any ? source : castedSource, element, arrayName, writeAccessors);
}
}
if (wroteFirstIf)
{
if (anyCount > 0)
{
// See "else " below
if (elements.Length - anyCount > 0)
{ // NOOP
}
else ilg.EndIf();
}
}
if (anyCount > 0)
{
if (elements.Length - anyCount > 0) ilg.InitElseIf();
else ilg.InitIf();
//.........这里部分代码省略.........
示例13: WritePrimitiveValue
private void WritePrimitiveValue(TypeDesc typeDesc, SourceInfo source, out Type returnType)
{
if (typeDesc == StringTypeDesc || typeDesc.FormatterName == "String")
{
source.Load(typeDesc.Type);
returnType = typeDesc.Type;
}
else
{
if (!typeDesc.HasCustomFormatter)
{
Type argType = typeDesc.Type;
// No ToString(Byte), compiler used ToString(Int16) instead.
if (argType == typeof(Byte))
argType = typeof(Int16);
// No ToString(UInt16), compiler used ToString(Int32) instead.
else if (argType == typeof(UInt16))
argType = typeof(Int32);
MethodInfo XmlConvert_ToString = typeof(XmlConvert).GetMethod(
"ToString",
CodeGenerator.StaticBindingFlags,
new Type[] { argType }
);
source.Load(typeDesc.Type);
ilg.Call(XmlConvert_ToString);
returnType = XmlConvert_ToString.ReturnType;
}
else
{
// Only these methods below that is non Static and need to ldarg("this") for Call.
BindingFlags bindingFlags = CodeGenerator.StaticBindingFlags;
if (typeDesc.FormatterName == "XmlQualifiedName")
{
bindingFlags = CodeGenerator.InstanceBindingFlags;
ilg.Ldarg(0);
}
MethodInfo FromXXX = typeof(XmlSerializationWriter).GetMethod(
"From" + typeDesc.FormatterName,
bindingFlags,
new Type[] { typeDesc.Type }
);
source.Load(typeDesc.Type);
ilg.Call(FromXXX);
returnType = FromXXX.ReturnType;
}
}
}
示例14: WriteEnumValue
private void WriteEnumValue(EnumMapping mapping, SourceInfo source, out Type returnType)
{
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(SR.Format(SR.XmlInternalErrorMethod, mapping.TypeDesc.Name));
#endif
// For enum, its write method (eg. Write1_Gender) could be called multiple times
// prior to its declaration.
MethodBuilder methodBuilder = EnsureMethodBuilder(typeBuilder,
methodName,
CodeGenerator.PrivateMethodAttributes,
typeof(string),
new Type[] { mapping.TypeDesc.Type });
ilg.Ldarg(0);
source.Load(mapping.TypeDesc.Type);
ilg.Call(methodBuilder);
returnType = typeof(string);
}