本文整理汇总了C#中System.Reflection.Emit.CodeGenerator.New方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenerator.New方法的具体用法?C# CodeGenerator.New怎么用?C# CodeGenerator.New使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.CodeGenerator
的用法示例。
在下文中一共展示了CodeGenerator.New方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginSetMembers
public void BeginSetMembers(CodeGenerator generator, ArgBuilder targetObject)
{
locMemberValues = generator.DeclareLocal(typeof(Dictionary<string, object>), "memberValues");
locDataTable = generator.DeclareLocal(typeof(DataTable), "dataTable");
generator.New(typeof(Dictionary<string, object>).GetConstructor(Type.EmptyTypes));
generator.Stloc(locMemberValues);
generator.New(typeof(DataTable).GetConstructor(Type.EmptyTypes));
generator.Stloc(locDataTable);
}
示例2: GetMemberValue
public void GetMemberValue(CodeGenerator generator, ArgBuilder targetObject, string memberName, ref LocalBuilder memberValue)
{
LocalBuilder locValue = generator.DeclareLocal(typeof(string));
Type targetType = memberValue.LocalType;
Type originalType = ConvertorGeneratorHelper.GetOriginalType(targetType);
generator.Ldarg(targetObject);
generator.Load(memberName);
generator.Call(typeof(NameValueCollection).GetMethod("get_Item", new Type[] { typeof(string) }));
generator.Stloc(locValue);
if (targetType.IsAssignableFrom(typeof(string)))
{
generator.Ldloc(locValue);
generator.Stloc(memberValue);
return;
}
else
{
generator.Ldloc(locValue);
generator.Call(typeof(string).GetMethod("IsNullOrEmpty"));
generator.Load(true);
generator.If(Cmp.NotEqualTo);
if (targetType == typeof(Guid))
{
generator.Ldloc(locValue);
generator.New(typeof(Guid).GetConstructor(new Type[] { typeof(string) }));
generator.Stloc(memberValue);
}
else
{
MethodInfo parseMethod = targetType.GetMethod("Parse", new Type[] { typeof(string) });
if (parseMethod != null)
{
generator.Ldloc(locValue);
generator.Call(parseMethod);
generator.Stloc(memberValue);
}
else
{
generator.Ldloc(locValue);
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();
}
}
示例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();
}