當前位置: 首頁>>代碼示例>>C#>>正文


C# Actions.OperatorInfo類代碼示例

本文整理匯總了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            
 }
開發者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


注:本文中的Microsoft.Scripting.Actions.OperatorInfo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。