本文整理汇总了C#中IKVM.Reflection.Emit.MethodBuilder.SetCustomAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBuilder.SetCustomAttribute方法的具体用法?C# MethodBuilder.SetCustomAttribute怎么用?C# MethodBuilder.SetCustomAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IKVM.Reflection.Emit.MethodBuilder
的用法示例。
在下文中一共展示了MethodBuilder.SetCustomAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoLink
internal override MethodBase DoLink()
{
RemapperTypeWrapper typeWrapper = (RemapperTypeWrapper)DeclaringType;
if(typeWrapper.IsInterface)
{
if([email protected] == null)
{
throw new InvalidOperationException(typeWrapper.Name + "." + m.Name + m.Sig);
}
MethodInfo interfaceMethod = typeWrapper.shadowType.GetMethod([email protected], typeWrapper.GetClassLoader().ArgTypeListFromSig(m.Sig));
if(interfaceMethod == null)
{
throw new InvalidOperationException(typeWrapper.Name + "." + m.Name + m.Sig);
}
// if any of the remapped types has a body for this interface method, we need a helper method
// to special invocation through this interface for that type
List<IKVM.Internal.MapXml.Class> specialCases = null;
foreach(IKVM.Internal.MapXml.Class c in map.assembly.Classes)
{
if(c.Methods != null)
{
foreach(IKVM.Internal.MapXml.Method mm in c.Methods)
{
if(mm.Name == m.Name && mm.Sig == m.Sig && mm.body != null)
{
if(specialCases == null)
{
specialCases = new List<IKVM.Internal.MapXml.Class>();
}
specialCases.Add(c);
break;
}
}
}
}
string[] throws;
if (m.throws == null)
{
throws = new string[0];
}
else
{
throws = new string[m.throws.Length];
for (int i = 0; i < throws.Length; i++)
{
throws[i] = m.throws[i].Class;
}
}
AttributeHelper.SetRemappedInterfaceMethod(typeWrapper.typeBuilder, m.Name, [email protected], throws);
MethodBuilder helper = null;
if(specialCases != null)
{
CodeEmitter ilgen;
Type[] temp = typeWrapper.GetClassLoader().ArgTypeListFromSig(m.Sig);
Type[] argTypes = new Type[temp.Length + 1];
temp.CopyTo(argTypes, 1);
argTypes[0] = typeWrapper.shadowType;
if(typeWrapper.helperTypeBuilder == null)
{
// FXBUG we use a nested helper class, because Reflection.Emit won't allow us to add a static method to the interface
// TODO now that we're on Whidbey we can remove this workaround
typeWrapper.helperTypeBuilder = typeWrapper.typeBuilder.DefineNestedType("__Helper", TypeAttributes.NestedPublic | TypeAttributes.Class | TypeAttributes.Sealed);
ilgen = CodeEmitter.Create(typeWrapper.helperTypeBuilder.DefineConstructor(MethodAttributes.Private, CallingConventions.Standard, Type.EmptyTypes));
ilgen.Emit(OpCodes.Ldnull);
ilgen.Emit(OpCodes.Throw);
ilgen.DoEmit();
AttributeHelper.HideFromJava(typeWrapper.helperTypeBuilder);
}
helper = typeWrapper.helperTypeBuilder.DefineMethod(m.Name, MethodAttributes.HideBySig | MethodAttributes.Public | MethodAttributes.Static, typeWrapper.GetClassLoader().RetTypeWrapperFromSig(m.Sig).TypeAsSignatureType, argTypes);
if(m.Attributes != null)
{
foreach(IKVM.Internal.MapXml.Attribute custattr in m.Attributes)
{
AttributeHelper.SetCustomAttribute(DeclaringType.GetClassLoader(), helper, custattr);
}
}
SetParameters(DeclaringType.GetClassLoader(), helper, m.Params);
ilgen = CodeEmitter.Create(helper);
foreach(IKVM.Internal.MapXml.Class c in specialCases)
{
TypeWrapper tw = typeWrapper.GetClassLoader().LoadClassByDottedName(c.Name);
ilgen.Emit(OpCodes.Ldarg_0);
ilgen.Emit(OpCodes.Isinst, tw.TypeAsTBD);
ilgen.Emit(OpCodes.Dup);
CodeEmitterLabel label = ilgen.DefineLabel();
ilgen.Emit(OpCodes.Brfalse_S, label);
for(int i = 1; i < argTypes.Length; i++)
{
ilgen.Emit(OpCodes.Ldarg, (short)i);
}
MethodWrapper mw = tw.GetMethodWrapper(m.Name, m.Sig, false);
mw.Link();
mw.EmitCallvirt(ilgen);
ilgen.Emit(OpCodes.Ret);
ilgen.MarkLabel(label);
ilgen.Emit(OpCodes.Pop);
}
for(int i = 0; i < argTypes.Length; i++)
{
//.........这里部分代码省略.........