本文整理汇总了C#中IKVM.Reflection.Emit.TypeBuilder.DefineConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.DefineConstructor方法的具体用法?C# TypeBuilder.DefineConstructor怎么用?C# TypeBuilder.DefineConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.DefineConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateConstructor
private static void CreateConstructor(TypeBuilder tb)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { invocationHandlerClass.TypeAsSignatureType });
CodeEmitter ilgen = CodeEmitter.Create(cb);
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Ldarg_1);
proxyConstructor.EmitCall(ilgen);
ilgen.Emit(OpCodes.Ret);
ilgen.DoEmit();
}
示例2: CreateStaticInitializer
private static void CreateStaticInitializer(TypeBuilder tb, List<ProxyMethod> methods)
{
ConstructorBuilder cb = tb.DefineConstructor(MethodAttributes.Static, CallingConventions.Standard, Type.EmptyTypes);
CodeEmitter ilgen = CodeEmitter.Create(cb);
CodeEmitterLocal callerID = ilgen.DeclareLocal([email protected]);
TypeBuilder tbCallerID = DynamicTypeWrapper.FinishContext.EmitCreateCallerID(tb, ilgen);
ilgen.Emit(OpCodes.Stloc, callerID);
// HACK we shouldn't create the nested type here (the outer type must be created first)
tbCallerID.CreateType();
ilgen.BeginExceptionBlock();
foreach (ProxyMethod method in methods)
{
method.mw.DeclaringType.EmitClassLiteral(ilgen);
ilgen.Emit(OpCodes.Ldstr, method.mw.Name);
TypeWrapper[] parameters = method.mw.GetParameters();
ilgen.Emit(OpCodes.Ldc_I4, parameters.Length);
ilgen.Emit(OpCodes.Newarr, CoreClasses.java.lang.Class.Wrapper.TypeAsArrayType);
for (int i = 0; i < parameters.Length; i++)
{
ilgen.Emit(OpCodes.Dup);
ilgen.Emit(OpCodes.Ldc_I4, i);
parameters[i].EmitClassLiteral(ilgen);
ilgen.Emit(OpCodes.Stelem_Ref);
}
if (javaLangClass_getMethod.HasCallerID)
{
ilgen.Emit(OpCodes.Ldloc, callerID);
}
javaLangClass_getMethod.EmitCallvirt(ilgen);
ilgen.Emit(OpCodes.Stsfld, method.fb);
}
CodeEmitterLabel label = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Leave_S, label);
ilgen.BeginCatchBlock(javaLangNoSuchMethodException.TypeAsExceptionType);
javaLangThrowable_getMessage.EmitCallvirt(ilgen);
javaLangNoClassDefFoundErrorConstructor.EmitNewobj(ilgen);
ilgen.Emit(OpCodes.Throw);
ilgen.EndExceptionBlock();
ilgen.MarkLabel(label);
ilgen.Emit(OpCodes.Ret);
ilgen.DoEmit();
}
示例3: EmitMapXmlMetadata
protected override void EmitMapXmlMetadata(TypeBuilder typeBuilder, ClassFile classFile, FieldWrapper[] fields, MethodWrapper[] methods)
{
Dictionary<string, IKVM.Internal.MapXml.Class> mapxml = classLoader.GetMapXmlClasses();
if(mapxml != null)
{
IKVM.Internal.MapXml.Class clazz;
if(mapxml.TryGetValue(classFile.Name, out clazz))
{
if(clazz.Attributes != null)
{
PublishAttributes(typeBuilder, clazz);
}
if(clazz.Properties != null)
{
PublishProperties(typeBuilder, clazz);
}
if(clazz.Fields != null)
{
foreach(IKVM.Internal.MapXml.Field field in clazz.Fields)
{
if(field.Attributes != null)
{
foreach(FieldWrapper fw in fields)
{
if(fw.Name == field.Name && fw.Signature == field.Sig)
{
FieldBuilder fb = fw.GetField() as FieldBuilder;
if(fb != null)
{
foreach(IKVM.Internal.MapXml.Attribute attr in field.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, fb, attr);
}
}
}
}
}
}
}
if(clazz.Constructors != null)
{
// HACK this isn't the right place to do this, but for now it suffices
foreach(IKVM.Internal.MapXml.Constructor constructor in clazz.Constructors)
{
// are we adding a new constructor?
if(GetMethodWrapper(StringConstants.INIT, constructor.Sig, false) == null)
{
if(constructor.body == null)
{
Console.Error.WriteLine("Error: Constructor {0}.<init>{1} in xml remap file doesn't have a body.", clazz.Name, constructor.Sig);
continue;
}
bool setmodifiers = false;
MethodAttributes attribs = 0;
MapModifiers(constructor.Modifiers, true, out setmodifiers, ref attribs);
Type returnType;
Type[] parameterTypes;
MapSignature(constructor.Sig, out returnType, out parameterTypes);
ConstructorBuilder cb = typeBuilder.DefineConstructor(attribs, CallingConventions.Standard, parameterTypes);
if(setmodifiers)
{
AttributeHelper.SetModifiers(cb, (Modifiers)constructor.Modifiers, false);
}
CompilerClassLoader.AddDeclaredExceptions(cb, constructor.throws);
CodeEmitter ilgen = CodeEmitter.Create(cb);
constructor.Emit(classLoader, ilgen);
ilgen.DoEmit();
if(constructor.Attributes != null)
{
foreach(IKVM.Internal.MapXml.Attribute attr in constructor.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, cb, attr);
}
}
}
}
foreach(IKVM.Internal.MapXml.Constructor constructor in clazz.Constructors)
{
if(constructor.Attributes != null)
{
foreach(MethodWrapper mw in methods)
{
if(mw.Name == "<init>" && mw.Signature == constructor.Sig)
{
ConstructorBuilder mb = mw.GetMethod() as ConstructorBuilder;
if(mb != null)
{
foreach(IKVM.Internal.MapXml.Attribute attr in constructor.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, mb, attr);
}
}
}
}
}
}
}
if(clazz.Methods != null)
{
// HACK this isn't the right place to do this, but for now it suffices
//.........这里部分代码省略.........