Skip to content

Instantly share code, notes, and snippets.

@jcbozonier
Created October 31, 2009 16:37
Show Gist options
  • Select an option

  • Save jcbozonier/223142 to your computer and use it in GitHub Desktop.

Select an option

Save jcbozonier/223142 to your computer and use it in GitHub Desktop.
private static void _GenerateMethod_With_Return(
MethodInfo methodInfo,
TypeBuilder typeBuilder,
string firstMethodName,
Type[] parameterTypes)
{
var returnType = methodInfo.ReturnType;
var methodBuilder = typeBuilder.DefineMethod(
firstMethodName,
MethodAttributes.Public | MethodAttributes.Virtual,
returnType,
parameterTypes);
methodBuilder.InitLocals = true;
var methodIl = methodBuilder.GetILGenerator();
methodIl.DeclareLocal(returnType);
methodIl.Emit(OpCodes.Ldloc_0);
methodIl.Emit(OpCodes.Ret);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment