本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.LoadMember方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.LoadMember方法的具体用法?C# CodeGenerator.LoadMember怎么用?C# CodeGenerator.LoadMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.LoadMember方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetMemberValue
public void SetMemberValue(CodeGenerator generator, ArgBuilder targetObject, string memberName, LocalBuilder memberValue)
{
generator.Ldarg(targetObject);
if (memberValue.LocalType.FullName.StartsWith("System.Nullable`1["))
{
generator.Ldloc(memberValue);
generator.Load(null);
generator.If(Cmp.EqualTo);
generator.LoadMember(typeof(DBNull).GetField("Value"));
generator.Stloc(memberValue);
generator.EndIf();
}
generator.Load(null);
generator.If(Cmp.EqualTo);
PropertyInfo columns = typeof(DataTable).GetProperty("Columns");
generator.Ldloc(locDataTable);
generator.LoadMember(columns);
generator.Load(memberName);
generator.Ldtoken(CommonUtils.GetOriginalTypeOfNullableType(memberValue.LocalType.IsEnum ? typeof(int) : memberValue.LocalType));
generator.Call(typeof(Type).GetMethod("GetTypeFromHandle", new Type[] { typeof(RuntimeTypeHandle) }));
generator.Call(typeof(DataColumnCollection).GetMethod("Add", new Type[] { typeof(string), typeof(Type) }));
generator.Pop();
generator.Ldloc(locMemberValues);
generator.Load(memberName);
generator.Ldloc(memberValue);
if (memberValue.LocalType.IsValueType)
{
generator.Box(memberValue.LocalType.IsEnum ? typeof(int) : memberValue.LocalType);
}
generator.Call(typeof(Dictionary<string, object>).GetMethod("Add"));
generator.Else();
generator.Ldarg(targetObject);
generator.Load(memberName);
generator.Ldloc(memberValue);
if (memberValue.LocalType.IsValueType)
{
generator.Box(memberValue.LocalType);
}
generator.Call(typeof(DataRow).GetMethod("set_Item", new Type[] { typeof(string), typeof(object) }));
generator.EndIf();
}
示例2: GetMemberValue
public void GetMemberValue(CodeGenerator generator, ArgBuilder targetObject, string memberName, ref LocalBuilder memberValue)
{
Type inputType = targetObject.ArgType;
MemberInfo memberInfo = ConvertorGeneratorHelper.GetMemberInfo(inputType, memberName);
if (memberInfo == null)
{
return;
}
Type srcMemberType = ConvertorGeneratorHelper.GetMemberType(memberInfo);
Type destMemberType = memberValue.LocalType;
if (memberValue.LocalType.IsAssignableFrom(srcMemberType))
{
generator.Ldarg(targetObject);
generator.LoadMember(memberInfo);
generator.Stloc(memberValue);
return;
}
Type converTargetType = ConvertorGeneratorHelper.GetOriginalType(destMemberType);
Type convertSourceType = ConvertorGeneratorHelper.GetOriginalType(srcMemberType);
//ת������
if (typeof(IConvertible).IsAssignableFrom(convertSourceType))
{
generator.Ldarg(targetObject);
generator.LoadMember(memberInfo);
if (convertSourceType.IsValueType)
{
generator.Box(srcMemberType);
}
//�Ƿ�Ϊ��
generator.Load(null);
generator.If(Cmp.NotEqualTo);
//�����Ϊ�գ���������ת��
generator.Ldarg(targetObject);
generator.LoadMember(memberInfo);
if (convertSourceType.IsValueType)
{
generator.Box(srcMemberType);
}
generator.Load(converTargetType);
generator.Call(typeof(Convert).GetMethod("ChangeType", new Type[] { typeof(object), typeof(Type) }));
if (destMemberType.IsValueType)
{
generator.UnboxAny(destMemberType);
}
generator.Stloc(memberValue);
//���Ϊ�գ������Ĭ��ֵ
generator.Else();
generator.LoadDefaultValue(destMemberType);
generator.Stloc(memberValue);
generator.EndIf();
}
}
示例3: GetMemberValue
public void GetMemberValue(CodeGenerator generator, ArgBuilder targetObject, string memberName, ref LocalBuilder memberValue)
{
LocalBuilder tempLocal = generator.DeclareLocal(typeof(object), "dataColumn");
Type targetType = memberValue.LocalType;
Type originalType = ConvertorGeneratorHelper.GetOriginalType(targetType);
generator.Ldarg(targetObject);
generator.Load(memberName);
generator.Call(typeof(DataRow).GetMethod("get_Item", new Type[] { typeof(string) }));
generator.Stloc(tempLocal);
generator.Ldloc(tempLocal);
generator.LoadMember(typeof(DBNull).GetField("Value", BindingFlags.Static | BindingFlags.Public));
generator.If(Cmp.EqualTo);
generator.LoadDefaultValue(targetType);
generator.Stloc(memberValue);
generator.Else();
generator.Ldloc(tempLocal);
generator.InternalILGenerator.Emit(OpCodes.Isinst, targetType);
generator.InternalILGenerator.Emit(OpCodes.Ldnull);
generator.InternalILGenerator.Emit(OpCodes.Cgt_Un);
generator.Load(true);
generator.If(Cmp.EqualTo);
generator.Ldloc(tempLocal);
if (targetType.IsValueType)
{
generator.UnboxAny(targetType);
}
generator.Stloc(memberValue);
generator.Else();
if (targetType == typeof(Guid))
{
generator.Ldloc(tempLocal);
generator.InternalILGenerator.Emit(OpCodes.Isinst, typeof(string));
generator.InternalILGenerator.Emit(OpCodes.Ldnull);
generator.InternalILGenerator.Emit(OpCodes.Cgt_Un);
generator.Load(true);
generator.If(Cmp.EqualTo);
generator.Ldloc(tempLocal);
generator.New(typeof(Guid).GetConstructor(new Type[] { typeof(string) }));
generator.Stloc(memberValue);
}
else
{
generator.Ldloc(tempLocal);
generator.InternalILGenerator.Emit(OpCodes.Isinst, typeof(IConvertible));
generator.InternalILGenerator.Emit(OpCodes.Ldnull);
generator.InternalILGenerator.Emit(OpCodes.Cgt_Un);
generator.Load(true);
generator.If(Cmp.EqualTo);
generator.Ldloc(tempLocal);
generator.Load(originalType);
generator.Call(typeof(Convert).GetMethod("ChangeType", new Type[] { typeof(object), typeof(Type) }));
if (targetType.IsValueType)
{
generator.UnboxAny(targetType);
}
generator.Stloc(memberValue);
}
generator.Else();
generator.LoadDefaultValue(targetType);
generator.Stloc(memberValue);
generator.EndIf();
generator.EndIf();
generator.EndIf();
}
示例4: DoGetStaticFieldGetDelegate
/// <summary>
/// Do Get Static Field Get Delegate
/// </summary>
/// <param name="targetModule"></param>
/// <param name="fieldInfo"></param>
/// <returns></returns>
protected static StaticDynamicMethodProxyHandler DoGetStaticFieldGetDelegate(
Module targetModule,
FieldInfo fieldInfo
)
{
Check.Require(targetModule, "targetModule");
Check.Require(fieldInfo, "fieldInfo");
Check.Require(fieldInfo.IsStatic, "fieldInfo MUST be static here.");
CodeGenerator gen = new CodeGenerator(targetModule);
gen.BeginMethod("dm" + Guid.NewGuid().ToString("N"), typeof(StaticDynamicMethodProxyHandler));
gen.LoadMember(fieldInfo);
CastValueToObject(gen, fieldInfo.FieldType);
return (StaticDynamicMethodProxyHandler)gen.EndMethod();
}