本文整理汇总了C#中Mono.CSharp.ResolveContext.LookupExtensionMethod方法的典型用法代码示例。如果您正苦于以下问题:C# ResolveContext.LookupExtensionMethod方法的具体用法?C# ResolveContext.LookupExtensionMethod怎么用?C# ResolveContext.LookupExtensionMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.ResolveContext
的用法示例。
在下文中一共展示了ResolveContext.LookupExtensionMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoResolve
protected override Expression DoResolve(ResolveContext ec)
{
eclass = ExprClass.PropertyAccess;
bool must_do_cs1540_check = false;
ec.Report.DisableReporting ();
bool res = ResolveGetter (ec, ref must_do_cs1540_check);
ec.Report.EnableReporting ();
if (!res) {
if (InstanceExpression != null) {
TypeSpec expr_type = InstanceExpression.Type;
ExtensionMethodGroupExpr ex_method_lookup = ec.LookupExtensionMethod (expr_type, Name, 0, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = InstanceExpression;
ex_method_lookup.SetTypeArguments (ec, targs);
return ex_method_lookup.Resolve (ec);
}
}
ResolveGetter (ec, ref must_do_cs1540_check);
return null;
}
if (!InstanceResolve (ec, false, must_do_cs1540_check))
return null;
//
// Only base will allow this invocation to happen.
//
if (IsBase && spec.IsAbstract) {
Error_CannotCallAbstractBase (ec, TypeManager.GetFullNameSignature (spec));
}
if (spec.MemberType.IsPointer && !ec.IsUnsafe){
UnsafeError (ec, loc);
}
if (!ec.IsObsolete) {
ObsoleteAttribute oa = spec.GetAttributeObsolete ();
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, ec.Report);
}
return this;
}
示例2: OverloadResolve
//.........这里部分代码省略.........
candidates_expanded.Add (m, candidate_args);
candidate_args = Arguments;
}
if (candidate_rate != 0 || has_inaccessible_candidates_only) {
if (msg_recorder != null)
msg_recorder.EndSession ();
continue;
}
msg_recorder = null;
candidates.Add (m);
}
} while (candidates.Count == 0 && GetBaseTypeMethods (ec));
ec.Report.SetPrinter (prev_recorder);
if (msg_recorder != null && !msg_recorder.IsEmpty) {
if (!may_fail)
msg_recorder.Merge (prev_recorder);
return null;
}
int candidate_top = candidates.Count;
if (candidate_top == 0) {
//
// When we found a top level method which does not match and it's
// not an extension method. We start extension methods lookup from here
//
if (InstanceExpression != null) {
var first = Methods.First ();
var arity = type_arguments == null ? -1 : type_arguments.Count;
ExtensionMethodGroupExpr ex_method_lookup = ec.LookupExtensionMethod (type, first.Name, arity, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = InstanceExpression;
ex_method_lookup.SetTypeArguments (ec, type_arguments);
return ex_method_lookup.OverloadResolve (ec, ref Arguments, may_fail, loc);
}
}
if (may_fail)
return null;
//
// Okay so we have failed to find exact match so we
// return error info about the closest match
//
if (best_candidate != null) {
if (CustomErrorHandler != null && !has_inaccessible_candidates_only && CustomErrorHandler.NoExactMatch (ec, best_candidate))
return null;
bool params_expanded = params_candidates != null && params_candidates.Contains (best_candidate);
if (NoExactMatch (ec, ref Arguments, params_expanded))
return null;
}
//
// We failed to find any method with correct argument count
//
if (Methods.First ().Kind == MemberKind.Constructor) {
ec.Report.SymbolRelatedToPreviousError (queried_type);
ec.Report.Error (1729, loc,
"The type `{0}' does not contain a constructor that takes `{1}' arguments",
TypeManager.CSharpName (queried_type), arg_count.ToString ());
} else {
示例3: DoResolve
public override Expression DoResolve (ResolveContext ec)
{
// Don't resolve already resolved expression
if (eclass != ExprClass.Invalid)
return this;
Expression expr_resolved = expr.Resolve (ec, ResolveFlags.VariableOrValue | ResolveFlags.MethodGroup);
if (expr_resolved == null)
return null;
//
// Next, evaluate all the expressions in the argument list
//
bool dynamic_arg = false;
if (arguments != null && !arguments_resolved)
arguments.Resolve (ec, out dynamic_arg);
Type expr_type = expr_resolved.Type;
mg = expr_resolved as MethodGroupExpr;
if (dynamic_arg || TypeManager.IsDynamicType (expr_type)) {
Arguments args;
DynamicMemberBinder dmb = expr_resolved as DynamicMemberBinder;
if (dmb != null) {
args = dmb.Arguments;
if (arguments != null)
args.AddRange (arguments);
} else if (mg == null) {
if (arguments == null)
args = new Arguments (1);
else
args = arguments;
args.Insert (0, new Argument (expr_resolved));
expr = null;
} else {
if (mg.IsBase) {
ec.Report.Error (1971, loc,
"The base call to method `{0}' cannot be dynamically dispatched. Consider casting the dynamic arguments or eliminating the base access",
mg.Name);
return null;
}
args = arguments;
if (mg.IsStatic != mg.IsInstance) {
if (args == null)
args = new Arguments (1);
if (mg.IsStatic) {
args.Insert (0, new Argument (new TypeOf (new TypeExpression (mg.DeclaringType, loc), loc).Resolve (ec), Argument.AType.DynamicStatic));
} else {
MemberAccess ma = expr as MemberAccess;
if (ma != null)
args.Insert (0, new Argument (ma.Left.Resolve (ec)));
else
args.Insert (0, new Argument (new This (loc).Resolve (ec)));
}
}
}
return new DynamicInvocation (expr as ATypeNameExpression, args, loc).Resolve (ec);
}
if (mg == null) {
if (expr_type != null && TypeManager.IsDelegateType (expr_type)){
return (new DelegateInvocation (
expr_resolved, arguments, loc)).Resolve (ec);
}
MemberExpr me = expr_resolved as MemberExpr;
if (me == null) {
expr_resolved.Error_UnexpectedKind (ec, ResolveFlags.MethodGroup, loc);
return null;
}
mg = ec.LookupExtensionMethod (me.Type, me.Name, loc);
if (mg == null) {
ec.Report.Error (1955, loc, "The member `{0}' cannot be used as method or delegate",
expr_resolved.GetSignatureForError ());
return null;
}
((ExtensionMethodGroupExpr)mg).ExtensionExpression = me.InstanceExpression;
}
mg = DoResolveOverload (ec);
if (mg == null)
return null;
MethodInfo method = (MethodInfo)mg;
if (method != null) {
type = TypeManager.TypeToCoreType (method.ReturnType);
// TODO: this is a copy of mg.ResolveMemberAccess method
Expression iexpr = mg.InstanceExpression;
if (method.IsStatic) {
if (iexpr == null ||
iexpr is This || iexpr is EmptyExpression ||
mg.IdenticalTypeName) {
//.........这里部分代码省略.........
示例4: OverloadResolve
//.........这里部分代码省略.........
if (msg_recorder != null)
msg_recorder.EndSession ();
continue;
}
msg_recorder = null;
candidates.Add (Methods [i]);
if (applicable_type == null)
applicable_type = decl_type;
else if (applicable_type != decl_type) {
is_sorted = false;
if (IsAncestralType (applicable_type, decl_type))
applicable_type = decl_type;
}
}
ec.Report.SetPrinter (prev_recorder);
if (msg_recorder != null && !msg_recorder.IsEmpty) {
if (!may_fail)
msg_recorder.Merge (prev_recorder);
return null;
}
int candidate_top = candidates.Count;
if (applicable_type == null) {
//
// When we found a top level method which does not match and it's
// not an extension method. We start extension methods lookup from here
//
if (InstanceExpression != null) {
ExtensionMethodGroupExpr ex_method_lookup = ec.LookupExtensionMethod (type, Name, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = InstanceExpression;
ex_method_lookup.SetTypeArguments (ec, type_arguments);
return ex_method_lookup.OverloadResolve (ec, ref Arguments, may_fail, loc);
}
}
if (may_fail)
return null;
//
// Okay so we have failed to find exact match so we
// return error info about the closest match
//
if (best_candidate != null) {
if (CustomErrorHandler != null && !has_inaccessible_candidates_only && CustomErrorHandler.NoExactMatch (ec, best_candidate))
return null;
AParametersCollection pd = TypeManager.GetParameterData (best_candidate);
bool cand_params = candidate_to_form != null && candidate_to_form.Contains (best_candidate);
if (arg_count == pd.Count || pd.HasParams) {
if (TypeManager.IsGenericMethodDefinition (best_candidate)) {
if (type_arguments == null) {
ec.Report.Error (411, loc,
"The type arguments for method `{0}' cannot be inferred from " +
"the usage. Try specifying the type arguments explicitly",
TypeManager.CSharpSignature (best_candidate));
return null;
}
Type[] g_args = TypeManager.GetGenericArguments (best_candidate);
if (type_arguments.Count != g_args.Length) {