本文整理汇总了C#中TypeBuilder.DefineConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.DefineConstructor方法的具体用法?C# TypeBuilder.DefineConstructor怎么用?C# TypeBuilder.DefineConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.DefineConstructor方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitCtor
static void EmitCtor (TypeBuilder genericFoo) {
ConstructorBuilder mb = genericFoo.DefineConstructor (MethodAttributes.Public, CallingConventions.Standard, null);
ILGenerator il = mb.GetILGenerator ();
for (int i = 0; i < 20; ++i)
il.Emit (OpCodes.Nop);
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Call, typeof (object).GetConstructors()[0]);
il.Emit (OpCodes.Ret);
ctor = mb;
}
示例2: AddConstructor
private static ConstructorInfo AddConstructor(TypeBuilder tb, MethodWrapper defaultConstructor, ConstructorInfo serializationConstructor, bool callReadObject)
{
ConstructorBuilder ctor = tb.DefineConstructor(MethodAttributes.Family, CallingConventions.Standard, new Type[] { JVM.Import(typeof(SerializationInfo)), JVM.Import(typeof(StreamingContext)) });
AttributeHelper.HideFromJava(ctor);
ctor.AddDeclarativeSecurity(SecurityAction.Demand, psetSerializationFormatter);
CodeEmitter ilgen = CodeEmitter.Create(ctor);
ilgen.Emit(OpCodes.Ldarg_0);
if (defaultConstructor != null)
{
defaultConstructor.EmitCall(ilgen);
}
else
{
ilgen.Emit(OpCodes.Ldarg_1);
ilgen.Emit(OpCodes.Ldarg_2);
ilgen.Emit(OpCodes.Call, serializationConstructor);
}
if (callReadObject)
{
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
TypeWrapper serializationHelper = ClassLoaderWrapper.LoadClassCritical("ikvm.internal.Serialization");
MethodWrapper mw = serializationHelper.GetMethodWrapper("readObject", "(Ljava.lang.Object;Lcli.System.Runtime.Serialization.SerializationInfo;)V", false);
mw.Link();
mw.EmitCall(ilgen);
}
ilgen.Emit(OpCodes.Ret);
return ctor;
}
示例3: EmitProxyConstructor
static void EmitProxyConstructor(TypeBuilder tb, FieldInfo thisField)
{
ConstructorBuilder ctor =
tb.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
new Type[1] { typeof(IntPtr) });
ILGenerator ilg = ctor.GetILGenerator();
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Call, typeof(object).GetConstructor(new Type[0]));
ilg.Emit(OpCodes.Ldarg_0);
ilg.Emit(OpCodes.Ldarg_1);
ilg.Emit(OpCodes.Stfld, thisField);
ilg.Emit(OpCodes.Ret);
}
示例4: AddConstr
// Create dummy constructor in given type
private void AddConstr( TypeBuilder t )
{
// Base is Object...
Type obj = Type.GetType("System.Object");
// Constructor in Object to call...
ConstructorInfo oci = obj.GetConstructor(new Type[0]);
// Start on the actual constructor..
ConstructorBuilder cb = t.DefineConstructor
(
MethodAttributes.Public,
CallingConventions.Standard,
new Type[0]
);
// Generate code...
ILGenerator il = cb.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, oci);
il.Emit(OpCodes.Ret);
}