- if (delegate_method == null) {
- Error_NoMatchingMethodForDelegate (ec, mg, type, loc);
- return null;
- }
-
- //
- // Check safe/unsafe of the delegate
- //
- if (!ec.InUnsafe){
- ParameterData param = TypeManager.GetParameterData (delegate_method);
- int count = param.Count;
-
- for (int i = 0; i < count; i++){
- if (param.ParameterType (i).IsPointer){
- Expression.UnsafeError (loc);
- return null;
- }
- }
- }
-
- //TODO: implement caching when performance will be low
- IMethodData md = TypeManager.GetMethod (
- TypeManager.DropGenericMethodArguments (delegate_method));
- if (md == null) {
- if (System.Attribute.GetCustomAttribute (delegate_method, TypeManager.conditional_attribute_type) != null) {
- Report.SymbolRelatedToPreviousError (delegate_method);
- Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature (delegate_method));
- return null;
- }
- } else {
- md.SetMemberIsUsed ();
- if (md.OptAttributes != null && md.OptAttributes.Search (TypeManager.conditional_attribute_type) != null) {
- Report.SymbolRelatedToPreviousError (delegate_method);
- Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature (delegate_method));
- return null;
- }
- }
-
- if (mg.InstanceExpression != null)
- delegate_instance_expression = mg.InstanceExpression.Resolve (ec);
- else if (ec.IsStatic) {
- if (!delegate_method.IsStatic) {
- Report.Error (120, loc, "`{0}': An object reference is required for the nonstatic field, method or property",
- TypeManager.CSharpSignature (delegate_method));
- return null;
- }
- delegate_instance_expression = null;
- } else
- delegate_instance_expression = ec.GetThis (loc);
-
- if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
- delegate_instance_expression = new BoxedCast (
- delegate_instance_expression, TypeManager.object_type);