• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Actions.OperatorInfo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Scripting.Actions.OperatorInfo的典型用法代码示例。如果您正苦于以下问题:C# OperatorInfo类的具体用法?C# OperatorInfo怎么用?C# OperatorInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OperatorInfo类属于Microsoft.Scripting.Actions命名空间,在下文中一共展示了OperatorInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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            
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:11,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:33,代码来源:DefaultBinder.Operations.cs


示例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)
     );
 }
开发者ID:apboyle,项目名称:ironruby,代码行数:11,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:8,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:13,代码来源:DefaultBinder.Operations.cs


示例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;
 }
开发者ID:apboyle,项目名称:ironruby,代码行数:29,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:10,代码来源:DefaultBinder.Operations.cs


示例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);
 }
开发者ID:apboyle,项目名称:ironruby,代码行数:9,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:8,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:77,代码来源:DefaultBinder.Operations.cs


示例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];
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:36,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:10,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:13,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:16,代码来源:DefaultBinder.Operations.cs


示例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;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:13,代码来源:DefaultBinder.Operations.cs


示例16: TryNumericComparison

        private DynamicMetaObject TryNumericComparison(OperatorInfo info, DynamicMetaObject[] args) {
            MethodInfo[] targets = FilterNonMethods(
                args[0].GetLimitType(),
                GetMember(OldDoOperationAction.Make(this, OperatorInfo.ExpressionTypeToOperator(info.Operator)),
                args[0].GetLimitType(),
                "Compare")
            );

            if (targets.Length > 0) {
                MethodBinder mb = MethodBinder.MakeBinder(this, targets[0].Name, targets);
                BindingTarget target = mb.MakeBindingTarget(CallTypes.None, args);
                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,
                        BindingRestrictions.Combine(target.RestrictedArguments)
                    );
                }
            }

            return null;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:31,代码来源:DefaultBinder.Operations.cs


示例17: TryPrimitiveCompare

        private static DynamicMetaObject TryPrimitiveCompare(OperatorInfo info, DynamicMetaObject[] args) {
            if (TypeUtils.GetNonNullableType(args[0].GetLimitType()) == TypeUtils.GetNonNullableType(args[1].GetLimitType()) &&
                TypeUtils.IsNumeric(args[0].GetLimitType())) {
                Expression arg0 = args[0].Expression;
                Expression arg1 = args[1].Expression;

                // TODO: Nullable<PrimitveType> Support
                Expression expr;
                switch (info.Operator) {
                    case ExpressionType.Equal: expr = Ast.Equal(arg0, arg1); break;
                    case ExpressionType.NotEqual: expr = Ast.NotEqual(arg0, arg1); break;
                    case ExpressionType.GreaterThan: expr = Ast.GreaterThan(arg0, arg1); break;
                    case ExpressionType.LessThan: expr = Ast.LessThan(arg0, arg1); break;
                    case ExpressionType.GreaterThanOrEqual: expr = Ast.GreaterThanOrEqual(arg0, arg1); break;
                    case ExpressionType.LessThanOrEqual: expr = Ast.LessThanOrEqual(arg0, arg1); break;
                    default: throw new InvalidOperationException();
                }

                return new DynamicMetaObject(
                    expr,
                    BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg0, args[0].GetLimitType()).Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg1, args[0].GetLimitType())).Merge(BindingRestrictions.Combine(args))
                );
            }

            return null;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:26,代码来源:DefaultBinder.Operations.cs


示例18: MakeOperatorRule

 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] // TODO: fix
 private DynamicMetaObject MakeOperatorRule(OperatorInfo info, Expression codeContext, DynamicMetaObject[] args) {
     return
         TryForwardOperator(info, codeContext, args) ??
         TryReverseOperator(info, codeContext, args) ??
         TryPrimitiveOperator(info, args) ??
         TryMakeDefaultUnaryRule(info, codeContext, args) ??
         MakeOperatorError(info, args);
 }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:DefaultBinder.Operations.cs


示例19: TryPrimitiveOperator

        private static DynamicMetaObject TryPrimitiveOperator(OperatorInfo info, DynamicMetaObject[] args) {
            if (args.Length == 2 &&
                TypeUtils.GetNonNullableType(args[0].GetLimitType()) == TypeUtils.GetNonNullableType(args[1].GetLimitType()) &&
                TypeUtils.IsArithmetic(args[0].GetLimitType())) {
                // TODO: Nullable<PrimitveType> Support
                Expression expr;
                DynamicMetaObject self = args[0].Restrict(args[0].GetLimitType());
                DynamicMetaObject arg0 = args[1].Restrict(args[0].GetLimitType());

                switch (info.Operator) {
                    case ExpressionType.Add: expr = Ast.Add(self.Expression, arg0.Expression); break;
                    case ExpressionType.Subtract: expr = Ast.Subtract(self.Expression, arg0.Expression); break;
                    case ExpressionType.Divide: expr = Ast.Divide(self.Expression, arg0.Expression); break;
                    case ExpressionType.Modulo: expr = Ast.Modulo(self.Expression, arg0.Expression); break;
                    case ExpressionType.Multiply: expr = Ast.Multiply(self.Expression, arg0.Expression); break;
                    case ExpressionType.LeftShift: expr = Ast.LeftShift(self.Expression, arg0.Expression); break;
                    case ExpressionType.RightShift: expr = Ast.RightShift(self.Expression, arg0.Expression); break;
                    case ExpressionType.And: expr = Ast.And(self.Expression, arg0.Expression); break;
                    case ExpressionType.Or: expr = Ast.Or(self.Expression, arg0.Expression); break;
                    case ExpressionType.ExclusiveOr: expr = Ast.ExclusiveOr(self.Expression, arg0.Expression); break;
                    default: throw new InvalidOperationException();
                }

                return new DynamicMetaObject(
                    expr,
                    self.Restrictions.Merge(arg0.Restrictions)
                );
            }

            return null;
        }
开发者ID:apboyle,项目名称:ironruby,代码行数:31,代码来源:DefaultBinder.Operations.cs


示例20: TryForwardOperator

        private DynamicMetaObject TryForwardOperator(OperatorInfo info, Expression codeContext, DynamicMetaObject[] args) {
            MethodInfo[] targets = GetApplicableMembers(args[0].GetLimitType(), info);
            BindingRestrictions restrictions = BindingRestrictions.Empty;

            if (targets.Length > 0) {
                return TryMakeBindingTarget(targets, args, codeContext, restrictions);
            }

            return null;
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:10,代码来源:DefaultBinder.Operations.cs



注:本文中的Microsoft.Scripting.Actions.OperatorInfo类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Calls.BindingTarget类代码示例发布时间:2022-05-26
下一篇:
C# Actions.MemberTracker类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap