本文整理汇总了C#中System.Reflection.Emit.TypeBuilder.DefineDefaultConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.DefineDefaultConstructor方法的具体用法?C# TypeBuilder.DefineDefaultConstructor怎么用?C# TypeBuilder.DefineDefaultConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.DefineDefaultConstructor方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitPageConstructors
/// <summary>
/// Emits constructors.
/// </summary>
private void EmitPageConstructors(TypeBuilder type)
{
ConstructorBuilder ctor;
// ILGenerator il;
ConstructorInfo ci;
//public instance void .ctor()
//{
// ldarg.0
// call instance void [PhpNetCore]PHP.Core.PhpPage::.ctor()
// ret
//}
ctor = type.DefineDefaultConstructor(MethodAttributes.Public);
ci = typeof(PhpPage).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance, // flags: instance family
null, // binder
new Type[] { }, // params
null); // modifiers
/* obsolete
//public instance void .ctor(class [PhpNetCore]PHP.Core.ConfigurationRecord)
//{
// ldarg.0
// ldarg.1
// call instance void [PhpNetCore]PHP.Core.PhpPage::.ctor(class [PhpNetCore]PHP.Core.ConfigurationRecord)
// ret
//}
ctor = type.DefineConstructor(
MethodAttributes.Public, // flags
CallingConventions.Standard, // calling convention
new Type[] {typeof(ConfigurationRecord)}); // params
ci = typeof(PhpPage).GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance, // flags: instance family
null, // binder
new Type[] {typeof(ConfigurationRecord)}, // params
null); // modifiers
il = ctor.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Call,ci);
il.Emit(OpCodes.Ret);
*/
}
示例2: GenerateConstructor
private static void GenerateConstructor(TypeBuilder dynamicType, string[] properties, List<FieldBuilder> fields)
{
const MethodAttributes CtorAttributes = MethodAttributes.RTSpecialName | MethodAttributes.SpecialName | MethodAttributes.HideBySig | MethodAttributes.Public;
var defaultCtor = dynamicType.DefineDefaultConstructor(CtorAttributes);
var ctor = dynamicType.DefineConstructor(CtorAttributes, CallingConventions.Standard, fields.Select(x => x.FieldType).ToArray());
var ctorIl = ctor.GetILGenerator();
ctorIl.Emit(OpCodes.Ldarg_0);
ctorIl.Emit(OpCodes.Call, defaultCtor);
for (var i = 0; i < properties.Length; i++)
{
var strParamName = properties[i];
var field = fields[i];
var builder3 = ctor.DefineParameter(i + 1, ParameterAttributes.None, strParamName);
ctorIl.Emit(OpCodes.Ldarg_0);
ctorIl.Emit(OpCodes.Ldarg, builder3.Position);
ctorIl.Emit(OpCodes.Stfld, field);
}
ctorIl.Emit(OpCodes.Ret);
AddDebuggerHiddenAttribute(ctor);
}
示例3: BuildMethod_ctor
/// <summary>
/// 构造函数
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private ConstructorBuilder BuildMethod_ctor(TypeBuilder type)
{
System.Reflection.MethodAttributes methodAttributes =
System.Reflection.MethodAttributes.Public
| System.Reflection.MethodAttributes.HideBySig;
return type.DefineDefaultConstructor(methodAttributes);
}
示例4: AddDefaultConstructor
/// <summary>
/// add a no arg constructor, which calls the default constructor of the supertype.
/// </summary>
public void AddDefaultConstructor(TypeBuilder builder,
MethodAttributes attrs) {
builder.DefineDefaultConstructor(attrs);
}
示例5: DefineDefaultConstructor
public static ConstructorBuilder DefineDefaultConstructor (TypeBuilder typeBuilder)
{
ConstructorBuilder constructorBuilder = typeBuilder.DefineDefaultConstructor (EmitConstants.PUBLIC_CONSTRUCTOR);
return constructorBuilder;
}
示例6: BuildMethod_ctor1
public void BuildMethod_ctor1(TypeBuilder type)
{
// Declaring method builder
// Method attributes
System.Reflection.MethodAttributes methodAttributes =
System.Reflection.MethodAttributes.Public
| System.Reflection.MethodAttributes.HideBySig;
ctor = type.DefineDefaultConstructor(methodAttributes);
}
示例7: GenerateWrapperConstructor
private static void GenerateWrapperConstructor(TypeBuilder newType, FieldInfo defaultValue)
{
ConstructorBuilder ctor = newType.DefineDefaultConstructor(MethodAttributes.Public);
}
示例8: GenerateConstructor
private static void GenerateConstructor(TypeBuilder type)
{
type.DefineDefaultConstructor (MethodAttributes.Public);
}
示例9: DefineEmptyDefaultConstr
/// <summary>adds an empty default constructor</summary>
private void DefineEmptyDefaultConstr(TypeBuilder boxBuilder) {
boxBuilder.DefineDefaultConstructor(MethodAttributes.Public);
}