Skip to content

Instantly share code, notes, and snippets.

@pietervp
Created June 29, 2012 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietervp/3018317 to your computer and use it in GitHub Desktop.
Save pietervp/3018317 to your computer and use it in GitHub Desktop.
private void MapInterfaceMethods(FieldInfo classToWrapField, TypeBuilderHelper typeBuilder)
{
//loop al interface methods
foreach (var methodInfo in InterfaceToImplement.GetMethods())
{
//define the method in the generated type
var emitter = typeBuilder.DefineMethod(methodInfo)
.Emitter
//this.[fieldName]
.ldarg_0
.ldfld(classToWrapField);
for (var index = 0; index < methodInfo.GetParameters().Length; index++)
//pushs all method arguments on the stack, so we can use them to
//call the targetMethod
emitter.ldarg(index + 1);
emitter
//this.[fieldName].[MethodToImplement]([parameters])
.callvirt(GetMappedMethod(methodInfo))
//return
.ret();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment