本文整理汇总了C#中Microsoft.Scripting.Actions.OperatorInfo类的典型用法代码示例。如果您正苦于以下问题:C# OperatorInfo类的具体用法?C# OperatorInfo怎么用?C# OperatorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OperatorInfo类属于Microsoft.Scripting.Actions命名空间,在下文中一共展示了OperatorInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeComparisonRule
private MetaObject MakeComparisonRule(OperatorInfo info, Expression codeContext, MetaObject[] args) {
return
TryComparisonMethod(info, codeContext, args[0], args) ?? // check the first type if it has an applicable method
TryComparisonMethod(info, codeContext, args[0], args) ?? // then check the second type
TryNumericComparison(info, args) ?? // try Compare: cmp(x,y) (>, <, >=, <=, ==, !=) 0
TryInvertedComparison(info, args[0], args) ?? // try inverting the operator & result (e.g. if looking for Equals try NotEquals, LessThan for GreaterThan)...
TryInvertedComparison(info, args[0], args) ?? // inverted binding on the 2nd type
TryNullComparisonRule(args) ?? // see if we're comparing to null w/ an object ref or a Nullable<T>
TryPrimitiveCompare(info, args) ?? // see if this is a primitive type where we're comparing the two values.
MakeOperatorError(info, args); // no comparisons are possible
}
示例2: TryNumericComparison
private DynamicMetaObject TryNumericComparison(OperatorInfo info, OverloadResolverFactory resolverFactory, DynamicMetaObject[] args) {
MethodInfo[] targets = FilterNonMethods(
args[0].GetLimitType(),
GetMember(
MemberRequestKind.Operation,
args[0].GetLimitType(),
"Compare"
)
);
if (targets.Length > 0) {
var resolver = resolverFactory.CreateOverloadResolver(args, new CallSignature(args.Length), CallTypes.None);
BindingTarget target = resolver.ResolveOverload(targets[0].Name, targets, NarrowingLevel.None, NarrowingLevel.All);
if (target.Success) {
Expression call = AstUtils.Convert(target.MakeExpression(), typeof(int));
switch (info.Operator) {
case ExpressionType.GreaterThan: call = Ast.GreaterThan(call, AstUtils.Constant(0)); break;
case ExpressionType.LessThan: call = Ast.LessThan(call, AstUtils.Constant(0)); break;
case ExpressionType.GreaterThanOrEqual: call = Ast.GreaterThanOrEqual(call, AstUtils.Constant(0)); break;
case ExpressionType.LessThanOrEqual: call = Ast.LessThanOrEqual(call, AstUtils.Constant(0)); break;
case ExpressionType.Equal: call = Ast.Equal(call, AstUtils.Constant(0)); break;
case ExpressionType.NotEqual: call = Ast.NotEqual(call, AstUtils.Constant(0)); break;
}
return new DynamicMetaObject(
call,
target.RestrictedArguments.GetAllRestrictions()
);
}
}
return null;
}
示例3: MakeOperatorError
private static DynamicMetaObject MakeOperatorError(OperatorInfo info, DynamicMetaObject[] args) {
return new DynamicMetaObject(
Ast.Throw(
AstUtils.ComplexCallHelper(
typeof(BinderOps).GetMethod("BadArgumentsForOperation"),
ArrayUtils.Insert((Expression)AstUtils.Constant(info.Operator), DynamicUtils.GetExpressions(args))
)
),
BindingRestrictions.Combine(args)
);
}
示例4: TryComparisonMethod
private DynamicMetaObject TryComparisonMethod(OperatorInfo info, OverloadResolverFactory resolverFactory, DynamicMetaObject target, DynamicMetaObject[] args) {
MethodInfo[] targets = GetApplicableMembers(target.GetLimitType(), info);
if (targets.Length > 0) {
return TryMakeBindingTarget(resolverFactory, targets, args, BindingRestrictions.Empty);
}
return null;
}
示例5: TryInvertedComparison
private MetaObject TryInvertedComparison(OperatorInfo info, MetaObject target, MetaObject[] args) {
Operators revOp = GetInvertedOperator(info.Operator);
OperatorInfo revInfo = OperatorInfo.GetOperatorInfo(revOp);
Debug.Assert(revInfo != null);
// try the 1st type's opposite function result negated
MethodBase[] targets = GetApplicableMembers(target.LimitType, revInfo);
if (targets.Length > 0) {
return TryMakeInvertedBindingTarget(targets, args);
}
return null;
}
示例6: TryMakeDefaultUnaryRule
private static DynamicMetaObject TryMakeDefaultUnaryRule(OperatorInfo info, DynamicMetaObject[] args) {
if (args.Length == 1) {
BindingRestrictions restrictions = BindingRestrictionsHelpers.GetRuntimeTypeRestriction(args[0].Expression, args[0].GetLimitType()).Merge(BindingRestrictions.Combine(args));
switch (info.Operator) {
case ExpressionType.IsTrue:
if (args[0].GetLimitType() == typeof(bool)) {
return args[0];
}
break;
case ExpressionType.Negate:
if (TypeUtils.IsArithmetic(args[0].GetLimitType())) {
return new DynamicMetaObject(
Ast.Negate(args[0].Expression),
restrictions
);
}
break;
case ExpressionType.Not:
if (TypeUtils.IsIntegerOrBool(args[0].GetLimitType())) {
return new DynamicMetaObject(
Ast.Not(args[0].Expression),
restrictions
);
}
break;
}
}
return null;
}
示例7: TryForwardOperator
private DynamicMetaObject TryForwardOperator(OperatorInfo info, OverloadResolverFactory resolverFactory, DynamicMetaObject[] args) {
MethodInfo[] targets = GetApplicableMembers(args[0].GetLimitType(), info);
BindingRestrictions restrictions = BindingRestrictions.Empty;
if (targets.Length > 0) {
return TryMakeBindingTarget(resolverFactory, targets, args, restrictions);
}
return null;
}
示例8: MakeOperatorRule
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] // TODO: fix
private DynamicMetaObject MakeOperatorRule(OperatorInfo info, OverloadResolverFactory resolverFactory, DynamicMetaObject[] args) {
return
TryForwardOperator(info, resolverFactory, args) ??
TryReverseOperator(info, resolverFactory, args) ??
TryPrimitiveOperator(info, args) ??
TryMakeDefaultUnaryRule(info, args) ??
MakeOperatorError(info, args);
}
示例9: TryComparisonMethod
private DynamicMetaObject TryComparisonMethod(OperatorInfo info, Expression codeContext, DynamicMetaObject target, DynamicMetaObject[] args) {
MethodInfo[] targets = GetApplicableMembers(target.GetLimitType(), info);
if (targets.Length > 0) {
return TryMakeBindingTarget(targets, args, codeContext, BindingRestrictions.Empty);
}
return null;
}
示例10: TryMakeDefaultUnaryRule
private static MetaObject TryMakeDefaultUnaryRule(OperatorInfo info, Expression codeContext, MetaObject[] args) {
if (args.Length == 1) {
Restrictions restrictions = Restrictions.GetTypeRestriction(args[0].Expression, args[0].LimitType).Merge(Restrictions.Combine(args));
switch (info.Operator) {
case Operators.IsTrue:
if (args[0].LimitType == typeof(bool)) {
return args[0];
}
break;
case Operators.Negate:
if (TypeUtils.IsArithmetic(args[0].LimitType)) {
return new MetaObject(
Ast.Negate(args[0].Expression),
restrictions
);
}
break;
case Operators.Not:
if (TypeUtils.IsIntegerOrBool(args[0].LimitType)) {
return new MetaObject(
Ast.Not(args[0].Expression),
restrictions
);
}
break;
case Operators.Documentation:
object[] attrs = args[0].LimitType.GetCustomAttributes(typeof(DocumentationAttribute), true);
string documentation = String.Empty;
if (attrs.Length > 0) {
documentation = ((DocumentationAttribute)attrs[0]).Documentation;
}
return new MetaObject(
Ast.Constant(documentation),
restrictions
);
case Operators.MemberNames:
if (typeof(IMembersList).IsAssignableFrom(args[0].LimitType)) {
return MakeIMembersListRule(codeContext, args[0]);
}
MemberInfo[] members = args[0].LimitType.GetMembers();
Dictionary<string, string> mems = new Dictionary<string, string>();
foreach (MemberInfo mi in members) {
mems[mi.Name] = mi.Name;
}
string[] res = new string[mems.Count];
mems.Keys.CopyTo(res, 0);
return new MetaObject(
Ast.Constant(res),
restrictions
);
case Operators.CallSignatures:
return MakeCallSignatureResult(CompilerHelpers.GetMethodTargets(args[0].LimitType), args[0]);
case Operators.IsCallable:
// IsCallable() is tightly tied to Call actions. So in general, we need the call-action providers to also
// provide IsCallable() status.
// This is just a rough fallback. We could also attempt to simulate the default CallBinder logic to see
// if there are any applicable calls targets, but that would be complex (the callbinder wants the argument list,
// which we don't have here), and still not correct.
bool callable = false;
if (typeof(Delegate).IsAssignableFrom(args[0].LimitType) ||
typeof(MethodGroup).IsAssignableFrom(args[0].LimitType)) {
callable = true;
}
return new MetaObject(
Ast.Constant(callable),
restrictions
);
}
}
return null;
}
示例11: GetFallbackMembers
/// <summary>
/// Gets alternate members which are specially recognized by the DLR for specific types when
/// all other member lookup fails.
/// </summary>
private static MethodInfo[] GetFallbackMembers(Type t, OperatorInfo info, MetaObject[] args, out Restrictions restrictions) {
// if we have an event we need to make a strongly-typed event handler
// TODO: Events, we need to look in the args and pull out the real values
if (t == typeof(EventTracker)) {
EventTracker et = ((EventTracker)args[0].Value);
if (info.Operator == Operators.InPlaceAdd) {
restrictions = GetFallbackRestrictions(t, et, args[0]);
return new MethodInfo[] { typeof(BinderOps).GetMethod("EventTrackerInPlaceAdd").MakeGenericMethod(et.Event.EventHandlerType) };
} else if (info.Operator == Operators.InPlaceSubtract) {
restrictions = GetFallbackRestrictions(t, et, args[0]);
return new MethodInfo[] { typeof(BinderOps).GetMethod("EventTrackerInPlaceRemove").MakeGenericMethod(et.Event.EventHandlerType) };
}
} else if (t == typeof(BoundMemberTracker)) {
BoundMemberTracker bmt = ((BoundMemberTracker)args[0].Value);
if (bmt.BoundTo.MemberType == TrackerTypes.Event) {
EventTracker et = ((EventTracker)bmt.BoundTo);
if (info.Operator == Operators.InPlaceAdd) {
restrictions = GetFallbackRestrictions(t, et, args[0]);
return new MethodInfo[] { typeof(BinderOps).GetMethod("BoundEventTrackerInPlaceAdd").MakeGenericMethod(et.Event.EventHandlerType) };
} else if (info.Operator == Operators.InPlaceSubtract) {
restrictions = GetFallbackRestrictions(t, et, args[0]);
return new MethodInfo[] { typeof(BinderOps).GetMethod("BoundEventTrackerInPlaceRemove").MakeGenericMethod(et.Event.EventHandlerType) };
}
}
}
restrictions = Restrictions.Empty;
return new MethodInfo[0];
}
示例12: TryInplaceOperator
private MetaObject TryInplaceOperator(OperatorInfo info, Expression codeContext, MetaObject[] args) {
Operators op = CompilerHelpers.InPlaceOperatorToOperator(info.Operator);
if (op != Operators.None) {
// recurse to try and get the non-inplace action...
return MakeOperatorRule(OperatorInfo.GetOperatorInfo(op), codeContext, args);
}
return null;
}
示例13: TryReverseOperator
private MetaObject TryReverseOperator(OperatorInfo info, Expression codeContext, MetaObject[] args) {
// we need a special conversion for the return type on MemberNames
if (info.Operator != Operators.MemberNames) {
if (args.Length > 0) {
MethodInfo[] targets = GetApplicableMembers(args[0].LimitType, info);
if (targets.Length > 0) {
return TryMakeBindingTarget(targets, args, codeContext, Restrictions.Empty);
}
}
}
return null;
}
示例14: TryForwardOperator
private MetaObject TryForwardOperator(OperatorInfo info, Expression codeContext, MetaObject[] args) {
// we need a special conversion for the return type on MemberNames
if (info.Operator != Operators.MemberNames) {
MethodInfo[] targets = GetApplicableMembers(args[0].LimitType, info);
Restrictions restrictions = Restrictions.Empty;
if (targets.Length == 0) {
targets = GetFallbackMembers(args[0].LimitType, info, args, out restrictions);
}
if (targets.Length > 0) {
return TryMakeBindingTarget(targets, args, codeContext, restrictions);
}
}
return null;
}
示例15: TryInvertedComparison
private DynamicMetaObject TryInvertedComparison(OperatorInfo info, OverloadResolverFactory resolverFactory, DynamicMetaObject target, DynamicMetaObject[] args) {
ExpressionType revOp = GetInvertedOperator(info.Operator);
OperatorInfo revInfo = OperatorInfo.GetOperatorInfo(revOp);
Debug.Assert(revInfo != null);
// try the 1st type's opposite function result negated
MethodBase[] targets = GetApplicableMembers(target.GetLimitType(), revInfo);
if (targets.Length > 0) {
return TryMakeInvertedBindingTarget(resolverFactory, targets, args);
}
return null;
}