本文整理汇总了C#中IKVM.Reflection.Emit.TypeBuilder.AddInterfaceImplementation方法的典型用法代码示例。如果您正苦于以下问题:C# TypeBuilder.AddInterfaceImplementation方法的具体用法?C# TypeBuilder.AddInterfaceImplementation怎么用?C# TypeBuilder.AddInterfaceImplementation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Emit.TypeBuilder
的用法示例。
在下文中一共展示了TypeBuilder.AddInterfaceImplementation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemapperTypeWrapper
internal RemapperTypeWrapper(CompilerClassLoader classLoader, IKVM.Internal.MapXml.Class c, IKVM.Internal.MapXml.Root map)
: base((Modifiers)c.Modifiers, c.Name)
{
this.classLoader = classLoader;
this.baseTypeWrapper = GetBaseWrapper(c);
classDef = c;
bool baseIsSealed = false;
shadowType = StaticCompiler.Universe.GetType(c.Shadows, true);
classLoader.SetRemappedType(shadowType, this);
Type baseType = shadowType;
Type baseInterface = null;
if(baseType.IsInterface)
{
baseInterface = baseType;
}
TypeAttributes attrs = TypeAttributes.Public;
if((c.Modifiers & IKVM.Internal.MapXml.MapModifiers.Interface) == 0)
{
attrs |= TypeAttributes.Class;
if(baseType.IsSealed)
{
baseIsSealed = true;
attrs |= TypeAttributes.Abstract | TypeAttributes.Sealed;
}
}
else
{
attrs |= TypeAttributes.Interface | TypeAttributes.Abstract;
baseType = null;
}
if((c.Modifiers & IKVM.Internal.MapXml.MapModifiers.Abstract) != 0)
{
attrs |= TypeAttributes.Abstract;
}
string name = c.Name.Replace('/', '.');
typeBuilder = classLoader.GetTypeWrapperFactory().ModuleBuilder.DefineType(name, attrs, baseIsSealed ? Types.Object : baseType);
if(c.Attributes != null)
{
foreach(IKVM.Internal.MapXml.Attribute custattr in c.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, typeBuilder, custattr);
}
}
if(baseInterface != null)
{
typeBuilder.AddInterfaceImplementation(baseInterface);
}
if(classLoader.EmitStackTraceInfo)
{
AttributeHelper.SetSourceFile(typeBuilder, Path.GetFileName(classLoader.options.remapfile));
}
if(baseIsSealed)
{
AttributeHelper.SetModifiers(typeBuilder, (Modifiers)c.Modifiers, false);
}
if(c.scope == IKVM.Internal.MapXml.Scope.Public)
{
// FXBUG we would like to emit an attribute with a Type argument here, but that doesn't work because
// of a bug in SetCustomAttribute that causes type arguments to be serialized incorrectly (if the type
// is in the same assembly). Normally we use AttributeHelper.FreezeDry to get around this, but that doesn't
// work in this case (no attribute is emitted at all). So we work around by emitting a string instead
AttributeHelper.SetRemappedClass(classLoader.assemblyBuilder, name, shadowType);
AttributeHelper.SetRemappedType(typeBuilder, shadowType);
}
List<MethodWrapper> methods = new List<MethodWrapper>();
if(c.Constructors != null)
{
foreach(IKVM.Internal.MapXml.Constructor m in c.Constructors)
{
methods.Add(new RemappedConstructorWrapper(this, m));
}
}
if(c.Methods != null)
{
foreach(IKVM.Internal.MapXml.Method m in c.Methods)
{
methods.Add(new RemappedMethodWrapper(this, m, map, false));
}
}
// add methods from our super classes (e.g. Throwable should have Object's methods)
if(!this.IsFinal && !this.IsInterface && this.BaseTypeWrapper != null)
{
foreach(MethodWrapper mw in BaseTypeWrapper.GetMethods())
{
RemappedMethodWrapper rmw = mw as RemappedMethodWrapper;
if(rmw != null && (rmw.IsPublic || rmw.IsProtected))
{
if(!FindMethod(methods, rmw.Name, rmw.Signature))
{
methods.Add(new RemappedMethodWrapper(this, rmw.XmlMethod, map, true));
}
}
}
}
//.........这里部分代码省略.........
示例2: EmitMapXmlMetadata
//.........这里部分代码省略.........
}
}
}
}
}
if(clazz.Methods != null)
{
// HACK this isn't the right place to do this, but for now it suffices
foreach(IKVM.Internal.MapXml.Method method in clazz.Methods)
{
// are we adding a new method?
if(GetMethodWrapper(method.Name, method.Sig, false) == null)
{
if(method.body == null)
{
Console.Error.WriteLine("Error: Method {0}.{1}{2} in xml remap file doesn't have a body.", clazz.Name, method.Name, method.Sig);
continue;
}
bool setmodifiers = false;
MethodAttributes attribs = method.MethodAttributes;
MapModifiers(method.Modifiers, false, out setmodifiers, ref attribs);
Type returnType;
Type[] parameterTypes;
MapSignature(method.Sig, out returnType, out parameterTypes);
MethodBuilder mb = typeBuilder.DefineMethod(method.Name, attribs, returnType, parameterTypes);
if(setmodifiers)
{
AttributeHelper.SetModifiers(mb, (Modifiers)method.Modifiers, false);
}
if([email protected] != null)
{
MethodWrapper mw = GetClassLoader().LoadClassByDottedName([email protected]).GetMethodWrapper([email protected], method.Sig, true);
mw.Link();
typeBuilder.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
}
CompilerClassLoader.AddDeclaredExceptions(mb, method.throws);
CodeEmitter ilgen = CodeEmitter.Create(mb);
method.Emit(classLoader, ilgen);
ilgen.DoEmit();
if(method.Attributes != null)
{
foreach(IKVM.Internal.MapXml.Attribute attr in method.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, mb, attr);
}
}
}
}
foreach(IKVM.Internal.MapXml.Method method in clazz.Methods)
{
if(method.Attributes != null)
{
foreach(MethodWrapper mw in methods)
{
if(mw.Name == method.Name && mw.Signature == method.Sig)
{
MethodBuilder mb = mw.GetMethod() as MethodBuilder;
if(mb != null)
{
foreach(IKVM.Internal.MapXml.Attribute attr in method.Attributes)
{
AttributeHelper.SetCustomAttribute(classLoader, mb, attr);
}
}
}
}
}
}
}
if(clazz.Interfaces != null)
{
foreach(IKVM.Internal.MapXml.Interface iface in clazz.Interfaces)
{
TypeWrapper tw = GetClassLoader().LoadClassByDottedName(iface.Name);
// NOTE since this interface won't be part of the list in the ImplementAttribute,
// it won't be visible from Java that the type implements this interface.
typeBuilder.AddInterfaceImplementation(tw.TypeAsBaseType);
if(iface.Methods != null)
{
foreach(IKVM.Internal.MapXml.Method m in iface.Methods)
{
MethodWrapper mw = tw.GetMethodWrapper(m.Name, m.Sig, false);
if(mw == null)
{
throw new InvalidOperationException("Method " + m.Name + m.Sig + " not found in interface " + tw.Name);
}
mw.Link();
MethodBuilder mb = mw.GetDefineMethodHelper().DefineMethod(this, typeBuilder, tw.Name + "/" + m.Name, MethodAttributes.Private | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.CheckAccessOnOverride);
AttributeHelper.HideFromJava(mb);
typeBuilder.DefineMethodOverride(mb, (MethodInfo)mw.GetMethod());
CodeEmitter ilgen = CodeEmitter.Create(mb);
m.Emit(classLoader, ilgen);
ilgen.DoEmit();
}
}
}
}
}
}
}