private ILMethodConctext DefineMethod( string methodName, bool isOverride, bool isStatic, Type returnType, Type[] parameterTypes )
{
if ( this._methodTable.ContainsKey( methodName ) )
{
throw new InvalidOperationException( String.Format( CultureInfo.CurrentCulture, "Method {0} is already defined.", methodName ) );
}
#if DEBUG
Contract.Assert( this._typeBuilder.BaseType != null, "this._typeBuilder.BaseType != null" );
#endif // DEBUG
MethodBuilder builder;
if ( isOverride )
{
var baseMethod =
this._typeBuilder.BaseType.GetRuntimeMethod(
methodName
);
builder =
this._typeBuilder.DefineMethod(
baseMethod.Name,
( baseMethod.Attributes | MethodAttributes.Final ) & ( ~MethodAttributes.Abstract ),
baseMethod.CallingConvention,
baseMethod.ReturnType,
baseMethod.GetParameterTypes()
);
this._typeBuilder.DefineMethodOverride(
builder,
baseMethod
);
}
else
{
builder =
this._typeBuilder.DefineMethod(
methodName,
MethodAttributes.Private | MethodAttributes.HideBySig | ( isStatic ? MethodAttributes.Static : 0 ),
isStatic ? CallingConventions.Standard : CallingConventions.HasThis,
returnType,
parameterTypes
);
}
this._methodTable[ methodName ] = builder;
return
new ILMethodConctext(
this.GetILGenerator( builder, parameterTypes ),
builder,
parameterTypes
);
}