Created
June 29, 2012 14:40
-
-
Save pietervp/3018317 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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