public static GetInvokeMethod ( |
||
ctx | ||
delType | System.TypeSpec | |
리턴 |
public static bool ImplicitStandardConversionExists(ResolveContext ec, MethodGroupExpr mg, TypeSpec target_type) { if (target_type == TypeManager.delegate_type || target_type == TypeManager.multicast_delegate_type) { return(false); } var invoke = Delegate.GetInvokeMethod(target_type); Arguments arguments = CreateDelegateMethodArguments(invoke.Parameters, invoke.Parameters.Types, mg.Location); return(mg.OverloadResolve(ec, ref arguments, null, OverloadResolver.Restrictions.CovariantDelegate | OverloadResolver.Restrictions.ProbingOnly) != null); }
public override Expression DoResolve(ResolveContext ec) { if (Arguments == null || Arguments.Count != 1) { ec.Report.Error(149, loc, "Method name expected"); return(null); } Argument a = Arguments [0]; if (!a.ResolveMethodGroup(ec)) { return(null); } Expression e = a.Expr; AnonymousMethodExpression ame = e as AnonymousMethodExpression; if (ame != null && RootContext.Version != LanguageVersion.ISO_1) { e = ame.Compatible(ec, type); if (e == null) { return(null); } return(e.Resolve(ec)); } method_group = e as MethodGroupExpr; if (method_group == null) { if (!TypeManager.IsDelegateType(e.Type)) { e.Error_UnexpectedKind(ec, ResolveFlags.MethodGroup | ResolveFlags.Type, loc); return(null); } // // An argument is not a method but another delegate // delegate_instance_expression = e; method_group = new MethodGroupExpr(new MemberInfo [] { Delegate.GetInvokeMethod(ec.Compiler, ec.CurrentType, e.Type) }, e.Type, loc); } return(base.DoResolve(ec)); }
public static bool ImplicitStandardConversionExists(ResolveContext ec, MethodGroupExpr mg, Type target_type) { if (target_type == TypeManager.delegate_type || target_type == TypeManager.multicast_delegate_type) { return(false); } mg.DelegateType = target_type; MethodInfo invoke = Delegate.GetInvokeMethod(ec.Compiler, null, target_type); Arguments arguments = CreateDelegateMethodArguments(TypeManager.GetParameterData(invoke), mg.Location); return(mg.OverloadResolve(ec, ref arguments, true, mg.Location) != null); }
protected override Expression DoResolve (ResolveContext ec) { TypeSpec del_type = InstanceExpr.Type; if (del_type == null) return null; // // Do only core overload resolution the rest of the checks has been // done on primary expression // method = Delegate.GetInvokeMethod (del_type); var res = new OverloadResolver (new MemberSpec[] { method }, OverloadResolver.Restrictions.DelegateInvoke, loc); var valid = res.ResolveMember<MethodSpec> (ec, ref arguments); if (valid == null && !res.BestCandidateIsDynamic) return null; type = method.ReturnType; eclass = ExprClass.Value; return this; }
protected override Expression DoResolve (ResolveContext ec) { if (Arguments == null || Arguments.Count != 1) { ec.Report.Error (149, loc, "Method name expected"); return null; } Argument a = Arguments [0]; if (!a.ResolveMethodGroup (ec)) return null; Expression e = a.Expr; AnonymousMethodExpression ame = e as AnonymousMethodExpression; if (ame != null && ec.Module.Compiler.Settings.Version != LanguageVersion.ISO_1) { e = ame.Compatible (ec, type); if (e == null) return null; return e.Resolve (ec); } method_group = e as MethodGroupExpr; if (method_group == null) { if (e.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { e = Convert.ImplicitConversionRequired (ec, e, type, loc); } else if (!e.Type.IsDelegate) { e.Error_UnexpectedKind (ec, ResolveFlags.MethodGroup | ResolveFlags.Type, loc); return null; } // // An argument is not a method but another delegate // method_group = new MethodGroupExpr (Delegate.GetInvokeMethod (e.Type), e.Type, loc); method_group.InstanceExpression = e; } return base.DoResolve (ec); }
public override Expression DoResolve(EmitContext ec) { if (InstanceExpr is EventExpr) { ((EventExpr)InstanceExpr).Error_CannotAssign(); return(null); } Type del_type = InstanceExpr.Type; if (del_type == null) { return(null); } if (Arguments != null) { foreach (Argument a in Arguments) { if (!a.Resolve(ec, loc)) { return(null); } } } if (!Delegate.VerifyApplicability(ec, del_type, Arguments, loc)) { return(null); } method = Delegate.GetInvokeMethod(ec.ContainerType, del_type); type = TypeManager.TypeToCoreType(method.ReturnType); eclass = ExprClass.Value; return(this); }
protected override Expression DoResolve(ResolveContext ec) { constructor_method = Delegate.GetConstructor(type); var invoke_method = Delegate.GetInvokeMethod(type); ResolveConditionalAccessReceiver(ec); Arguments arguments = CreateDelegateMethodArguments(ec, invoke_method.Parameters, invoke_method.Parameters.Types, loc); method_group = method_group.OverloadResolve(ec, ref arguments, this, OverloadResolver.Restrictions.CovariantDelegate); if (method_group == null) { return(null); } var delegate_method = method_group.BestCandidate; if (delegate_method.DeclaringType.IsNullableType) { ec.Report.Error(1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type", delegate_method.GetSignatureForError()); return(null); } if (!AllowSpecialMethodsInvocation) { Invocation.IsSpecialMethodInvocation(ec, delegate_method, loc); } ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr; if (emg != null) { method_group.InstanceExpression = emg.ExtensionExpression; TypeSpec e_type = emg.ExtensionExpression.Type; if (TypeSpec.IsValueType(e_type)) { ec.Report.Error(1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates", delegate_method.GetSignatureForError(), e_type.GetSignatureForError()); } } TypeSpec rt = method_group.BestCandidateReturnType; if (rt.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { rt = ec.BuiltinTypes.Object; } if (!Delegate.IsTypeCovariant(ec, rt, invoke_method.ReturnType)) { Expression ret_expr = new TypeExpression(delegate_method.ReturnType, loc); Error_ConversionFailed(ec, delegate_method, ret_expr); } if (method_group.IsConditionallyExcluded) { ec.Report.SymbolRelatedToPreviousError(delegate_method); MethodOrOperator m = delegate_method.MemberDefinition as MethodOrOperator; if (m != null && m.IsPartialDefinition) { ec.Report.Error(762, loc, "Cannot create delegate from partial method declaration `{0}'", delegate_method.GetSignatureForError()); } else { ec.Report.Error(1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature(delegate_method)); } } var expr = method_group.InstanceExpression; if (expr != null && (expr.Type.IsGenericParameter || !TypeSpec.IsReferenceType(expr.Type))) { method_group.InstanceExpression = new BoxedCast(expr, ec.BuiltinTypes.Object); } eclass = ExprClass.Value; return(this); }
public override Expression DoResolve(ResolveContext ec) { constructor_method = Delegate.GetConstructor(ec.Compiler, ec.CurrentType, type); MethodInfo invoke_method = Delegate.GetInvokeMethod(ec.Compiler, ec.CurrentType, type); method_group.DelegateType = type; method_group.CustomErrorHandler = this; Arguments arguments = CreateDelegateMethodArguments(TypeManager.GetParameterData(invoke_method), loc); method_group = method_group.OverloadResolve(ec, ref arguments, false, loc); if (method_group == null) { return(null); } delegate_method = (MethodInfo)method_group; if (TypeManager.IsNullableType(delegate_method.DeclaringType)) { ec.Report.Error(1728, loc, "Cannot create delegate from method `{0}' because it is a member of System.Nullable<T> type", TypeManager.GetFullNameSignature(delegate_method)); return(null); } Invocation.IsSpecialMethodInvocation(ec, delegate_method, loc); ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr; if (emg != null) { delegate_instance_expression = emg.ExtensionExpression; Type e_type = delegate_instance_expression.Type; if (TypeManager.IsValueType(e_type)) { ec.Report.Error(1113, loc, "Extension method `{0}' of value type `{1}' cannot be used to create delegates", TypeManager.CSharpSignature(delegate_method), TypeManager.CSharpName(e_type)); } } Type rt = TypeManager.TypeToCoreType(delegate_method.ReturnType); Expression ret_expr = new TypeExpression(rt, loc); if (!Delegate.IsTypeCovariant(ret_expr, (TypeManager.TypeToCoreType(invoke_method.ReturnType)))) { Error_ConversionFailed(ec, delegate_method, ret_expr); } if (Invocation.IsMethodExcluded(delegate_method, loc)) { ec.Report.SymbolRelatedToPreviousError(delegate_method); MethodOrOperator m = TypeManager.GetMethod(delegate_method) as MethodOrOperator; if (m != null && m.IsPartialDefinition) { ec.Report.Error(762, loc, "Cannot create delegate from partial method declaration `{0}'", TypeManager.CSharpSignature(delegate_method)); } else { ec.Report.Error(1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute", TypeManager.CSharpSignature(delegate_method)); } } DoResolveInstanceExpression(ec); eclass = ExprClass.Value; return(this); }