本文整理汇总了C#中System.Reflection.Emit.ConstructorBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ConstructorBuilder类的具体用法?C# ConstructorBuilder怎么用?C# ConstructorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConstructorBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了ConstructorBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DefineDelegate
/// <summary>
/// Defines an inner Delegate type for the method to be invoked from Objective-C runtime.
/// </summary>
// TODO: Refactor
private Type DefineDelegate (TypeBuilder typeBuilder, MethodInfo methodInfo, out ConstructorBuilder constructorBuilder)
{
// Get info about the target method
Type returnType = GetReturnType (methodInfo);
Type nativeReturnType = TypeHelper.GetNativeType (returnType, this.Is64Bits);
Type[] nativeParameterTypes = TypeHelper.GetNativeParameterTypes (methodInfo, this.Is64Bits);
// TODO: Refactor
// Remove first parameter of the extension method
nativeParameterTypes = ArrayHelper.TrimLeft (nativeParameterTypes, 1);
// Create the array of parameters for the delegate's invoke method
nativeParameterTypes = ArrayHelper.Prepend (nativeParameterTypes, typeof(IntPtr), typeof(IntPtr));
// Assign some names to parameters (for easy debugging)
String[] parameterNames = TypeHelper.GetParameterNames (methodInfo);
// TODO: Refactor
// Remove first parameter of the extension method
parameterNames = ArrayHelper.TrimLeft (parameterNames, 1);
String[] nativeParameterNames = new String[nativeParameterTypes.Length];
Array.Copy (parameterNames, 0, nativeParameterNames, 2, parameterNames.Length);
nativeParameterNames [0] = "receiver";
nativeParameterNames [1] = "selector";
// Create a unique delegate name
String name = GetUniqueName (methodInfo) + "_Invoker";
// Create a delegate
TypeBuilder delegateBuilder = EmitHelper.DefineNestedDelegate (typeBuilder, name, nativeReturnType, nativeParameterTypes, nativeParameterNames, out constructorBuilder);
// Generate the type
return delegateBuilder.CreateType ();
}
示例2: ILConstructorDebugImpl
public ILConstructorDebugImpl(ConstructorBuilder constructor, IILGenForbidenInstructions forbidenInstructions, SourceCodeWriter sourceCodeWriter)
{
_constructor = constructor;
_sourceCodeWriter = sourceCodeWriter;
_forbidenInstructions = forbidenInstructions;
_expectedLength = 64;
}
示例3: Compile
internal void Compile(ConstructorBuilder c)
{
if (Builder == null)
{
int ofs = (c.IsStatic ? 0 : 1);
Builder = c.DefineParameter(this.Index + ofs, this.Attributes, this.Name);
}
}
示例4: ConstructorBuilderHelper
/// <summary>
/// Initializes a new instance of the <see cref="ConstructorBuilder"/> class
/// with the specified parameters.
/// </summary>
/// <param name="typeBuilder">Associated <see cref="TypeBuilderHelper"/>.</param>
/// <param name="constructorBuilder">A <see cref="ConstructorBuilder"/></param>
public ConstructorBuilderHelper(TypeBuilderHelper typeBuilder, ConstructorBuilder constructorBuilder)
: base(typeBuilder)
{
if (constructorBuilder == null) throw new ArgumentNullException("constructorBuilder");
_constructorBuilder = constructorBuilder;
_constructorBuilder.SetCustomAttribute(Type.Assembly.BLToolkitAttribute);
}
示例5: DefineParams
public static void DefineParams(ConstructorBuilder constructorBuilder, IEnumerable<RppParameterInfo> constructorParams)
{
int index = 1;
foreach (var param in constructorParams)
{
constructorBuilder.DefineParameter(index++, ParameterAttributes.None, RppClass.StringConstructorArgName(param.Name));
}
}
示例6: EnhanceType
private void EnhanceType(TypeBuilder mainType, FieldBuilder handlerFieldBuilder, ConstructorBuilder constructorBuilder)
{
Assert.IsTrue( !m_enhanceInvoked );
Assert.IsNotNull(mainType);
Assert.IsNotNull(handlerFieldBuilder);
Assert.IsNotNull(constructorBuilder);
m_enhanceInvoked = true;
}
示例7: DefineLoaderType
protected void DefineLoaderType(ConstructorBuilder factoryConstructorBuilder)
{
loaderBuilder.AddInterfaceImplementation(typeof(IFactoryLoader));
loaderBuilder.DefineDefaultConstructor(MethodAttributes.Public);
var methodIl = loaderBuilder.DefineMethod("CreateFactory", MethodAttributes.Public | MethodAttributes.Virtual,
typeof(object), factoryContructorParameters).GetILGenerator();
methodIl.Emit(OpCodes.Ldarg_1);
methodIl.Emit(OpCodes.Newobj, factoryConstructorBuilder);
methodIl.Emit(OpCodes.Ret);
}
示例8: EmitConstrucorIL
public void EmitConstrucorIL(ConstructorBuilder builder)
{
ConstructorInfo conObj = typeof(object).GetConstructor(new Type[0]);
//call constructor of base object
ILGenerator il = builder.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, conObj);
il.Emit(OpCodes.Ret);
}
示例9: DefineParameterNames
private static void DefineParameterNames(
ConstructorBuilder constructor,
ConstructorMetadata constructorMetadata)
{
for (var i = 0; i < constructorMetadata.Parameters.Length; i++)
{
var parameter = constructorMetadata.Parameters[i];
constructor.DefineParameter(parameter.Sequence, ParameterAttributes.None, parameter.Name);
}
}
示例10: 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;
}
示例11: DefineConstructorBuilder
public ConstructorBuilder DefineConstructorBuilder()
{
if (IsConstructor)
{
ConstructorBuilder = Parent.TypeBuilder.DefineConstructor(
GetMethodModifiers(),
CallingConventions.Standard,
GetArgumentTypes());
}
else
{
ConstructorBuilder = Parent.TypeBuilder.DefineTypeInitializer();
}
return ConstructorBuilder;
}
示例12: GetInitConstructorIL
protected ILGenerator GetInitConstructorIL(ConstructorBuilder constructorBuilder, Dictionary<TypeFactoryMap, FieldBuilder> singletonFields)
{
var constrIl = constructorBuilder.GetILGenerator();
constrIl.Emit(OpCodes.Ldarg_0);
constrIl.Emit(OpCodes.Call, typeof(object).GetConstructor(Type.EmptyTypes));
foreach (var fieldPair in singletonFields)
{
var injectableGetSingletonMethod = typeof(IInjectableModule).GetMethod("GetSingleton").MakeGenericMethod(fieldPair.Key.BaseType);
constrIl.Emit(OpCodes.Ldarg_0);
constrIl.Emit(OpCodes.Ldarg_1);
constrIl.Emit(OpCodes.Ldstr, fieldPair.Key.Name);
constrIl.Emit(OpCodes.Callvirt, injectableGetSingletonMethod);
constrIl.Emit(OpCodes.Stfld, fieldPair.Value);
}
return constrIl;
}
示例13: PrepareSelf
/// <summary>
/// Creates a ConstructorBuilder for current constructor entity.
/// </summary>
public override void PrepareSelf()
{
// todo: remove when we support static ctors
if(IsStatic)
throw new LensCompilerException(CompilerMessages.ConstructorStatic);
if (ConstructorBuilder != null || IsImported)
return;
var ctx = ContainerType.Context;
if (ArgumentTypes == null)
ArgumentTypes = Arguments == null
? new Type[0]
: Arguments.Values.Select(fa => fa.GetArgumentType(ctx)).ToArray();
ConstructorBuilder = ContainerType.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, ArgumentTypes);
Generator = ConstructorBuilder.GetILGenerator(Context.ILStreamSize);
}
示例14: EmitCtor
private void EmitCtor(PropertyAndField[] properties, ConstructorBuilder method)
{
ILGenerator iLGenerator = method.GetILGenerator();
iLGenerator.Emit(OpCodes.Ldarg_0);
iLGenerator.Emit(OpCodes.Call, ObjectType.GetConstructor(Type.EmptyTypes));
int index = 0;
if (0 < properties.Length)
{
do
{
iLGenerator.Emit(OpCodes.Ldarg_0);
int arg = index + 1;
iLGenerator.Emit(OpCodes.Ldarg, arg);
iLGenerator.Emit(OpCodes.Stfld, properties[index].Field);
index = arg;
}
while (index < properties.Length);
}
iLGenerator.Emit(OpCodes.Ret);
}
示例15: ConstructorEmitter
internal ConstructorEmitter(AbstractTypeEmitter maintype, params ArgumentReference[] arguments)
{
this.maintype = maintype;
var args = ArgumentsUtil.InitializeAndConvert(arguments);
builder = maintype.TypeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, args);
}