本文整理汇总了C#中Microsoft.Scripting.Actions.Calls.BindingTarget类的典型用法代码示例。如果您正苦于以下问题:C# BindingTarget类的具体用法?C# BindingTarget怎么用?C# BindingTarget使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingTarget类属于Microsoft.Scripting.Actions.Calls命名空间,在下文中一共展示了BindingTarget类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MakeInvalidParametersError
public override Actions.ErrorInfo MakeInvalidParametersError(BindingTarget target) {
Expression exceptionValue;
switch (target.Result) {
case BindingResult.AmbiguousMatch:
exceptionValue = MakeAmbiguousCallError(target);
break;
case BindingResult.IncorrectArgumentCount:
exceptionValue = MakeIncorrectArgumentCountError(target);
break;
case BindingResult.CallFailure:
exceptionValue = MakeCallFailureError(target);
break;
default: throw new InvalidOperationException();
}
return Actions.ErrorInfo.FromException(exceptionValue);
}
开发者ID:toddb,项目名称:ironruby,代码行数:16,代码来源:RubyBinder.cs
示例2: MakeAmbiguousCallError
private Expression MakeAmbiguousCallError(BindingTarget target) {
StringBuilder sb = new StringBuilder(string.Format("Found multiple methods for '{0}': ", target.Name));
string outerComma = "";
foreach (MethodTarget mt in target.AmbiguousMatches) {
Type[] types = mt.GetParameterTypes();
string innerComma = "";
sb.Append(outerComma);
sb.Append(target.Name);
sb.Append('(');
foreach (Type t in types) {
sb.Append(innerComma);
sb.Append(GetTypeName(t));
innerComma = ", ";
}
sb.Append(')');
outerComma = ", ";
}
return Methods.MakeAmbiguousMatchError.OpCall(AstUtils.Constant(sb.ToString()));
}
开发者ID:toddb,项目名称:ironruby,代码行数:22,代码来源:RubyBinder.cs
示例3: MakeIncorrectArgumentCountError
private static ErrorInfo MakeIncorrectArgumentCountError(BindingTarget target) {
int minArgs = Int32.MaxValue;
int maxArgs = Int32.MinValue;
foreach (int argCnt in target.ExpectedArgumentCount) {
minArgs = System.Math.Min(minArgs, argCnt);
maxArgs = System.Math.Max(maxArgs, argCnt);
}
return ErrorInfo.FromException(
Ast.Call(
typeof(BinderOps).GetMethod("TypeErrorForIncorrectArgumentCount", new Type[] {
typeof(string), typeof(int), typeof(int) , typeof(int), typeof(int), typeof(bool), typeof(bool)
}),
Ast.Constant(target.Name, typeof(string)), // name
Ast.Constant(minArgs), // min formal normal arg cnt
Ast.Constant(maxArgs), // max formal normal arg cnt
Ast.Constant(0), // default cnt
Ast.Constant(target.ActualArgumentCount), // args provided
Ast.Constant(false), // hasArgList
Ast.Constant(false) // kwargs provided
)
);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:23,代码来源:DefaultBinder.cs
示例4: MakeAmbiguousCallError
private ErrorInfo MakeAmbiguousCallError(BindingTarget target) {
StringBuilder sb = new StringBuilder("Multiple targets could match: ");
string outerComma = "";
foreach (MethodTarget mt in target.AmbiguousMatches) {
Type[] types = mt.GetParameterTypes();
string innerComma = "";
sb.Append(outerComma);
sb.Append(target.Name);
sb.Append('(');
foreach (Type t in types) {
sb.Append(innerComma);
sb.Append(GetTypeName(t));
innerComma = ", ";
}
sb.Append(')');
outerComma = ", ";
}
return ErrorInfo.FromException(
Ast.Call(
typeof(BinderOps).GetMethod("SimpleTypeError"),
Ast.Constant(sb.ToString(), typeof(string))
)
);
}
开发者ID:mscottford,项目名称:ironruby,代码行数:27,代码来源:DefaultBinder.cs
示例5: CallMethod
/// <summary>
/// Performs binding against a set of overloaded methods using the specified arguments. The arguments are
/// consumed as specified by the CallSignature object.
/// </summary>
/// <param name="minLevel">TODO.</param>
/// <param name="maxLevel">TODO.</param>
/// <param name="resolver">Overload resolver.</param>
/// <param name="targets">The methods to be called</param>
/// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
/// <param name="target">The resulting binding target which can be used for producing error information.</param>
/// <param name="name">The name of the method or null to use the name from targets.</param>
/// <returns>A meta object which results from the call.</returns>
public DynamicMetaObject CallMethod(DefaultOverloadResolver resolver, IList<MethodBase> targets, BindingRestrictions restrictions, string name,
NarrowingLevel minLevel, NarrowingLevel maxLevel, out BindingTarget target) {
ContractUtils.RequiresNotNull(resolver, "resolver");
ContractUtils.RequiresNotNullItems(targets, "targets");
ContractUtils.RequiresNotNull(restrictions, "restrictions");
// attempt to bind to an individual method
target = resolver.ResolveOverload(name ?? GetTargetName(targets), targets, minLevel, maxLevel);
if (target.Success) {
// if we succeed make the target for the rule
return new DynamicMetaObject(
target.MakeExpression(),
restrictions.Merge(
MakeSplatTests(resolver.CallType, resolver.Signature, resolver.Arguments).
Merge(target.RestrictedArguments.GetAllRestrictions())
)
);
}
// make an error rule
return MakeInvalidParametersRule(resolver, restrictions, target);
}
开发者ID:jschementi,项目名称:iron,代码行数:35,代码来源:DefaultBinder.MethodCalls.cs
示例6: MakeInvalidParametersRule
// TODO: revisit
private DynamicMetaObject MakeInvalidParametersRule(DefaultOverloadResolver binder, BindingRestrictions restrictions, BindingTarget bt) {
var args = binder.Arguments;
BindingRestrictions restriction = MakeSplatTests(binder.CallType, binder.Signature, true, args);
// restrict to the exact type of all parameters for errors
for (int i = 0; i < args.Count; i++) {
args[i] = args[i].Restrict(args[i].GetLimitType());
}
return MakeError(
binder.MakeInvalidParametersError(bt),
restrictions.Merge(BindingRestrictions.Combine(args).Merge(restriction)),
typeof(object)
);
}
开发者ID:jschementi,项目名称:iron,代码行数:17,代码来源:DefaultBinder.MethodCalls.cs
示例7: MakeCallFailureError
private Expression MakeCallFailureError(BindingTarget target) {
foreach (CallFailure cf in target.CallFailures) {
switch (cf.Reason) {
case CallFailureReason.ConversionFailure:
foreach (ConversionResult cr in cf.ConversionResults) {
if (cr.Failed) {
if (typeof(Proc).IsAssignableFrom(cr.To)) {
return Methods.CreateArgumentsErrorForProc.OpCall(AstUtils.Constant(cr.GetArgumentTypeName(Binder)));
}
Debug.Assert(typeof(BlockParam).IsSealed);
if (cr.To == typeof(BlockParam)) {
return Methods.CreateArgumentsErrorForMissingBlock.OpCall();
}
string toType;
if (cr.To.IsGenericType && cr.To.GetGenericTypeDefinition() == typeof(Union<,>)) {
var g = cr.To.GetGenericArguments();
toType = Binder.GetTypeName(g[0]) + " or " + Binder.GetTypeName(g[1]);
} else {
toType = Binder.GetTypeName(cr.To);
}
return Methods.CreateTypeConversionError.OpCall(
AstUtils.Constant(cr.GetArgumentTypeName(Binder)),
AstUtils.Constant(toType)
);
}
}
break;
case CallFailureReason.TypeInference:
// TODO: Display generic parameters so it's clear what we couldn't infer.
return Methods.CreateArgumentsError.OpCall(
AstUtils.Constant(String.Format("generic arguments could not be infered for method '{0}'", target.Name))
);
case CallFailureReason.DuplicateKeyword:
case CallFailureReason.UnassignableKeyword:
default:
throw new InvalidOperationException();
}
}
throw new InvalidOperationException();
}
开发者ID:andreakn,项目名称:ironruby,代码行数:45,代码来源:RubyOverloadResolver.cs
示例8: CallMethod
/// <summary>
/// Performs binding against a set of overloaded methods using the specified arguments. The arguments are
/// consumed as specified by the CallSignature object.
/// </summary>
/// <param name="parameterBinder">ParameterBinder used to map arguments to parameters.</param>
/// <param name="targets">The methods to be called</param>
/// <param name="args">The arguments for the call</param>
/// <param name="signature">The call signature which specified how the arguments will be consumed</param>
/// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
/// <param name="maxLevel">The maximum narrowing level for arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <param name="minLevel">The minimum narrowing level for the arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <param name="target">The resulting binding target which can be used for producing error information.</param>
/// <param name="name">The name of the method or null to use the name from targets.</param>
/// <returns>A meta object which results from the call.</returns>
public DynamicMetaObject CallMethod(ParameterBinder parameterBinder, IList<MethodBase> targets, IList<DynamicMetaObject> args, CallSignature signature, BindingRestrictions restrictions, NarrowingLevel minLevel, NarrowingLevel maxLevel, string name, out BindingTarget target) {
return CallWorker(
parameterBinder,
targets,
args,
signature,
CallTypes.None,
restrictions,
minLevel,
maxLevel,
name,
out target
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:28,代码来源:DefaultBinder.MethodCalls.cs
示例9: AddArgumentRestrictions
internal void AddArgumentRestrictions(MetaObjectBuilder/*!*/ metaBuilder, BindingTarget/*!*/ bindingTarget) {
var args = GetActualArguments();
var restrictedArgs = bindingTarget.Success ? bindingTarget.RestrictedArguments.GetObjects() : args.Arguments;
for (int i = _firstRestrictedArg; i < restrictedArgs.Count; i++) {
var arg = (bindingTarget.Success ? restrictedArgs[i] : restrictedArgs[i].Restrict(restrictedArgs[i].GetLimitType()));
if (i >= args.FirstSplattedArg && i <= _lastSplattedArg) {
metaBuilder.AddCondition(arg.Restrictions.ToExpression());
} else {
metaBuilder.AddRestriction(arg.Restrictions);
}
}
// Adds condition for collapsed arguments - it is the same whether we succeed or not:
var splatCondition = GetCollapsedArgsCondition();
if (splatCondition != null) {
metaBuilder.AddCondition(splatCondition);
}
}
开发者ID:andreakn,项目名称:ironruby,代码行数:20,代码来源:RubyOverloadResolver.cs
示例10: MakeAmbiguousCallError
private Expression MakeAmbiguousCallError(BindingTarget target) {
StringBuilder sb = new StringBuilder(string.Format("Found multiple methods for '{0}': ", target.Name));
string outerComma = "";
foreach (MethodCandidate candidate in target.AmbiguousMatches) {
IList<ParameterWrapper> parameters = candidate.GetParameters();
string innerComma = "";
sb.Append(outerComma);
sb.Append(target.Name);
sb.Append('(');
foreach (var param in parameters) {
if (!param.IsHidden) {
sb.Append(innerComma);
sb.Append(Binder.GetTypeName(param.Type));
if (param.ProhibitNull) {
sb.Append('!');
}
innerComma = ", ";
}
}
sb.Append(')');
outerComma = ", ";
}
return Methods.MakeAmbiguousMatchError.OpCall(AstUtils.Constant(sb.ToString()));
}
开发者ID:andreakn,项目名称:ironruby,代码行数:28,代码来源:RubyOverloadResolver.cs
示例11: MakeIncorrectArgumentCountError
private Expression MakeIncorrectArgumentCountError(BindingTarget target) {
int minArgs = Int32.MaxValue;
int maxArgs = Int32.MinValue;
foreach (int argCnt in target.ExpectedArgumentCount) {
minArgs = System.Math.Min(minArgs, argCnt);
maxArgs = System.Math.Max(maxArgs, argCnt);
}
return Methods.MakeWrongNumberOfArgumentsError.OpCall(
AstUtils.Constant(target.ActualArgumentCount),
AstUtils.Constant(minArgs));
}
开发者ID:toddb,项目名称:ironruby,代码行数:12,代码来源:RubyBinder.cs
示例12: MakeCallFailureError
private ErrorInfo MakeCallFailureError(BindingTarget target) {
foreach (CallFailure cf in target.CallFailures) {
switch (cf.Reason) {
case CallFailureReason.ConversionFailure:
foreach (ConversionResult cr in cf.ConversionResults) {
if (cr.Failed) {
return ErrorInfo.FromException(
Ast.Call(
typeof(BinderOps).GetMethod("SimpleTypeError"),
Ast.Constant(String.Format("expected {0}, got {1}", GetTypeName(cr.To), GetTypeName(cr.From)))
)
);
}
}
break;
case CallFailureReason.DuplicateKeyword:
return ErrorInfo.FromException(
Ast.Call(
typeof(BinderOps).GetMethod("TypeErrorForDuplicateKeywordArgument"),
Ast.Constant(target.Name, typeof(string)),
Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string)) // TODO: Report all bad arguments?
)
);
case CallFailureReason.UnassignableKeyword:
return ErrorInfo.FromException(
Ast.Call(
typeof(BinderOps).GetMethod("TypeErrorForExtraKeywordArgument"),
Ast.Constant(target.Name, typeof(string)),
Ast.Constant(SymbolTable.IdToString(cf.KeywordArguments[0]), typeof(string)) // TODO: Report all bad arguments?
)
);
default: throw new InvalidOperationException();
}
}
throw new InvalidOperationException();
}
开发者ID:mscottford,项目名称:ironruby,代码行数:36,代码来源:DefaultBinder.cs
示例13: MakeInvalidSplatteeError
private ErrorInfo MakeInvalidSplatteeError(BindingTarget target) {
return ErrorInfo.FromException(
Ast.Call(typeof(BinderOps).GetMethod("InvalidSplatteeError"),
AstUtils.Constant(target.Name),
AstUtils.Constant(Binder.GetTypeName(_invalidSplattee.GetLimitType()))
)
);
}
开发者ID:jschementi,项目名称:iron,代码行数:8,代码来源:DefaultOverloadResolver.cs
示例14: MakeInvalidParametersError
public override ErrorInfo MakeInvalidParametersError(BindingTarget target) {
if (target.Result == BindingResult.InvalidArguments && _invalidSplattee != null) {
return MakeInvalidSplatteeError(target);
}
return base.MakeInvalidParametersError(target);
}
开发者ID:jschementi,项目名称:iron,代码行数:6,代码来源:DefaultOverloadResolver.cs
示例15: MakeInvalidParametersRule
private static DynamicMetaObject MakeInvalidParametersRule(CallTypes callType, CallSignature signature, DefaultBinder binder, IList<DynamicMetaObject> args, BindingRestrictions restrictions, BindingTarget bt) {
BindingRestrictions restriction = MakeSplatTests(callType, signature, true, args);
// restrict to the exact type of all parameters for errors
for (int i = 0; i < args.Count; i++) {
args[i] = args[i].Restrict(args[i].GetLimitType());
}
return MakeError(
binder.MakeInvalidParametersError(bt),
restrictions.Merge(BindingRestrictions.Combine(args).Merge(restriction))
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:13,代码来源:DefaultBinder.MethodCalls.cs
示例16: CallWorker
private DynamicMetaObject CallWorker(ParameterBinder parameterBinder, IList<MethodBase> targets, IList<DynamicMetaObject> args, CallSignature signature, CallTypes callType, BindingRestrictions restrictions, NarrowingLevel minLevel, NarrowingLevel maxLevel, string name, out BindingTarget target) {
ContractUtils.RequiresNotNull(parameterBinder, "parameterBinder");
ContractUtils.RequiresNotNullItems(args, "args");
ContractUtils.RequiresNotNullItems(targets, "targets");
ContractUtils.RequiresNotNull(restrictions, "restrictions");
DynamicMetaObject[] finalArgs;
SymbolId[] argNames;
if (callType == CallTypes.ImplicitInstance) {
GetArgumentNamesAndTypes(signature, ArrayUtils.RemoveFirst(args), out argNames, out finalArgs);
finalArgs = ArrayUtils.Insert(args[0], finalArgs);
} else {
GetArgumentNamesAndTypes(signature, args, out argNames, out finalArgs);
}
// attempt to bind to an individual method
MethodBinder binder = MethodBinder.MakeBinder(
this,
name ?? GetTargetName(targets),
targets,
argNames,
minLevel,
maxLevel);
target = binder.MakeBindingTarget(callType, finalArgs);
if (target.Success) {
// if we succeed make the target for the rule
return new DynamicMetaObject(
target.MakeExpression(parameterBinder),
restrictions.Merge(MakeSplatTests(callType, signature, args).Merge(BindingRestrictions.Combine(target.RestrictedArguments)))
);
}
// make an error rule
return MakeInvalidParametersRule(callType, signature, this, args, restrictions, target);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:36,代码来源:DefaultBinder.MethodCalls.cs
示例17: CallInstanceMethod
/// <summary>
/// Performs binding against a set of overloaded methods using the specified arguments and the specified
/// instance argument. The arguments are consumed as specified by the CallSignature object.
/// </summary>
/// <param name="parameterBinder">ParameterBinder used to map arguments to parameters.</param>
/// <param name="targets">The methods to be called</param>
/// <param name="args">The arguments for the call</param>
/// <param name="signature">The call signature which specified how the arguments will be consumed</param>
/// <param name="restrictions">Additional restrictions which should be applied to the resulting MetaObject.</param>
/// <param name="instance">The instance which will be provided for dispatching to an instance method.</param>
/// <param name="maxLevel">The maximum narrowing level for arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <param name="minLevel">The minimum narrowing level for the arguments. The current narrowing level is flowed thorugh to the DefaultBinder.</param>
/// <param name="target">The resulting binding target which can be used for producing error information.</param>
/// <param name="name">The name of the method or null to use the name from targets.</param>
/// <returns>A meta object which results from the call.</returns>
public DynamicMetaObject CallInstanceMethod(ParameterBinder parameterBinder, IList<MethodBase> targets, DynamicMetaObject instance, IList<DynamicMetaObject> args, CallSignature signature, BindingRestrictions restrictions, NarrowingLevel minLevel, NarrowingLevel maxLevel, string name, out BindingTarget target) {
return CallWorker(
parameterBinder,
targets,
ArrayUtils.Insert(instance, args),
signature,
CallTypes.ImplicitInstance,
restrictions,
minLevel,
maxLevel,
name,
out target
);
}
开发者ID:octavioh,项目名称:ironruby,代码行数:29,代码来源:DefaultBinder.MethodCalls.cs
示例18: MakeInvalidParametersError
public virtual ErrorInfo MakeInvalidParametersError(BindingTarget target) {
switch (target.Result) {
case BindingResult.CallFailure: return MakeCallFailureError(target);
case BindingResult.AmbiguousMatch: return MakeAmbiguousCallError(target);
case BindingResult.IncorrectArgumentCount: return MakeIncorrectArgumentCountError(target);
default: throw new InvalidOperationException();
}
}
开发者ID:mscottford,项目名称:ironruby,代码行数:8,代码来源:DefaultBinder.cs
示例19: MakeCallFailureError
private Expression MakeCallFailureError(BindingTarget target) {
foreach (CallFailure cf in target.CallFailures) {
switch (cf.Reason) {
case CallFailureReason.ConversionFailure:
foreach (ConversionResult cr in cf.ConversionResults) {
if (cr.Failed) {
if (typeof(Proc).IsAssignableFrom(cr.To)) {
return Methods.CreateArgumentsErrorForProc.OpCall(AstUtils.Constant(cr.GetArgumentTypeName(Binder)));
}
Debug.Assert(typeof(BlockParam).IsSealed);
if (cr.To == typeof(BlockParam)) {
return Methods.CreateArgumentsErrorForMissingBlock.OpCall();
}
return Methods.CreateTypeConversionError.OpCall(
AstUtils.Constant(cr.GetArgumentTypeName(Binder)),
AstUtils.Constant(Binder.GetTypeName(cr.To)));
}
}
break;
case CallFailureReason.DuplicateKeyword:
case CallFailureReason.UnassignableKeyword:
default: throw new InvalidOperationException();
}
}
throw new InvalidOperationException();
}
开发者ID:xerxesb,项目名称:ironruby,代码行数:29,代码来源:RubyOverloadResolver.cs
示例20: MakeInvalidParametersError
public override Microsoft.Scripting.Actions.ErrorInfo MakeInvalidParametersError(BindingTarget target) {
Expression exceptionValue;
switch (target.Result) {
case BindingResult.AmbiguousMatch:
exceptionValue = MakeAmbiguousCallError(target);
break;
case BindingResult.IncorrectArgumentCount:
exceptionValue = MakeIncorrectArgumentCountError(target);
break;
case BindingResult.CallFailure:
exceptionValue = MakeCallFailureError(target);
break;
case BindingResult.NoCallableMethod:
exceptionValue = Methods.CreateArgumentsError.OpCall(
AstUtils.Constant(String.Format("Method '{0}' is not callable", target.Name))
);
break;
default:
throw new InvalidOperationException();
}
return Microsoft.Scripting.Actions.ErrorInfo.FromException(exceptionValue);
}
开发者ID:andreakn,项目名称:ironruby,代码行数:26,代码来源:RubyOverloadResolver.cs
注:本文中的Microsoft.Scripting.Actions.Calls.BindingTarget类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论