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

C# DynamicMetaObject类代码示例

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

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



DynamicMetaObject类属于命名空间,在下文中一共展示了DynamicMetaObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SetBoundValue

 protected override DynamicMetaObject SetBoundValue(OverloadResolverFactory factory, ActionBinder binder, Type type, DynamicMetaObject value, DynamicMetaObject instance, DynamicMetaObject errorSuggestion) {
     return new DynamicMetaObject(
         Expression.Condition(
             Ast.Call(
                 typeof(PythonOps).GetMethod("SlotTrySetValue"),
                 ((PythonOverloadResolverFactory)factory)._codeContext,
                 AstUtils.Constant(GetSlot(), typeof(PythonTypeSlot)),
                 AstUtils.Convert(
                     instance.Expression,
                     typeof(object)
                 ),
                 AstUtils.Constant(DynamicHelpers.GetPythonTypeFromType(type)),
                 value.Expression
             ),
             AstUtils.Convert(value.Expression, typeof(object)),
             errorSuggestion != null ?
                 errorSuggestion.Expression :
                 Expression.Throw(
                     Expression.Call(
                         typeof(PythonOps).GetMethod("AttributeErrorForMissingAttribute", new Type[] { typeof(object), typeof(string) }),
                         instance.Expression,
                         Expression.Constant(Name)
                     ),
                     typeof(object)
                 )
         ),
         BindingRestrictions.Empty
     );
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:29,代码来源:CustomAttributeTracker.cs


示例2: BindCatchAllPrimitive

        public static DynamicMetaObject BindCatchAllPrimitive(DynamicMetaObject target, DynamicMetaObject[] args, Type returnType)
        {
            var method = typeof(BonsaiPrimitives).GetMethodsWith<CatchAllPrimitiveAttribute>(
                (mi, capi) =>
                       capi.Type == null || (
                           target.LimitType.IsAssignableFrom(capi.Type) || (
                               capi.Type.IsGenericTypeDefinition &&
                               target.LimitType.IsGenericType &&
                               capi.Type.GetGenericArguments().Length == target.LimitType.GetGenericArguments().Length &&
                               capi.Type.MakeGenericType(target.LimitType.GetGenericArguments()).IsAssignableFrom(target.LimitType))))
                .FirstOrDefault();

            // assume that if the method is generic than the matched type is also generic and it gets the same parameters
            if (method != null && method.IsGenericMethodDefinition)
                method = method.MakeGenericMethod(target.LimitType.GetGenericArguments());

            if (method != null) {
                return new DynamicMetaObject(
                       Expression.Convert(
                           Expression.Call(
                               null,
                               method,
                               new Expression[] {
                                    Expression.Convert(target.Expression, method.GetParameters()[0].ParameterType),
                                    args[0].Expression,
                                    Expression.NewArrayInit(
                                        typeof(object),
                                        args.Subarray(1).Select(a => Expression.Convert(a.Expression, typeof(object))))
                                }),
                           returnType),
                       BindingRestrictions.GetTypeRestriction(target.Expression, target.Value.GetType()));
            } else {
                throw new Exception("Binding failed");
            }
        }
开发者ID:eugen,项目名称:Bonsai,代码行数:35,代码来源:BonsaiPrimitives.cs


示例3: BindSetIndex

        public override DynamicMetaObject BindSetIndex(SetIndexBinder binder, DynamicMetaObject[] indexes, DynamicMetaObject value) {
            //
            // Demand Full Trust to proceed with the binding.
            //

            new PermissionSet(PermissionState.Unrestricted).Demand();

            ComMethodDesc method;
            var target = _callable.DispatchComObject;
            var name = _callable.MemberName;

            bool holdsNull = value.Value == null && value.HasValue;
            if (target.TryGetPropertySetter(name, out method, value.LimitType, holdsNull) ||
                target.TryGetPropertySetterExplicit(name, out method, value.LimitType, holdsNull)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref indexes);
                isByRef = isByRef.AddLast(false);
                var result = BindComInvoke(method, indexes.AddLast(value), binder.CallInfo, isByRef);

                // Make sure to return the value; some languages need it.
                return new DynamicMetaObject(
                    Expression.Block(result.Expression, Expression.Convert(value.Expression, typeof(object))),
                    result.Restrictions
                );
            }

            return base.BindSetIndex(binder, indexes, value);
        }
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:28,代码来源:DispCallableMetaObject.cs


示例4: TryBindGetMember

        public static bool TryBindGetMember(GetMemberBinder binder, DynamicMetaObject instance, out DynamicMetaObject result, bool delayInvocation) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");

            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                var comGetMember = new ComGetMemberBinder(binder, delayInvocation);
                result = instance.BindGetMember(comGetMember);
                if (result.Expression.Type.IsValueType) {
                    result = new DynamicMetaObject(
                        Expression.Convert(result.Expression, typeof(object)),
                        result.Restrictions
                    );
                }
                return true;
            } else {
                result = null;
                return false;
            }
        }
开发者ID:nlhepler,项目名称:mono,代码行数:25,代码来源:ComBinder.cs


示例5: BindInvokeMember

        public override DynamicMetaObject/*!*/ BindInvokeMember(InvokeMemberBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            DynamicMetaObject errorSuggestion = null;
            if (_baseMetaObject != null) {
                errorSuggestion = _baseMetaObject.BindInvokeMember(action, args);
            }
            
            CodeContext context = BinderState.GetBinderState(action).Context;
            IPythonObject sdo = Value;
            PythonTypeSlot foundSlot;

            if (TryGetGetAttribute(context, sdo.PythonType, out foundSlot)) {
                // we'll always fetch the value, go ahead and invoke afterwards.
                return BindingHelpers.GenericCall(action, this, args);
            }

            bool isOldStyle;
            bool systemTypeResolution;
            foundSlot = FindSlot(context, action.Name, sdo, out isOldStyle, out systemTypeResolution);
            if (foundSlot != null && !systemTypeResolution) {
                // we found the member in the type dictionary, not a .NET type, go ahead and
                // do the get & invoke.
                return BindingHelpers.GenericCall(action, this, args);
            }

            // it's a normal .NET member, let the calling language handle it how it usually does
            return action.FallbackInvokeMember(this, args, errorSuggestion);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:27,代码来源:MetaUserObject.cs


示例6: FallbackDeleteMember

        public override DynamicMetaObject FallbackDeleteMember(DynamicMetaObject self, DynamicMetaObject errorSuggestion) {
            if (self.NeedsDeferral()) {
                return Defer(self);
            }

            return Context.Binder.DeleteMember(Name, self, new PythonOverloadResolverFactory(_context.Binder, AstUtils.Constant(Context.SharedContext)));
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:7,代码来源:PythonDeleteMemberBinder.cs


示例7: FallbackBinaryOperation

        public override DynamicMetaObject FallbackBinaryOperation(
            DynamicMetaObject target,
            DynamicMetaObject arg,
            DynamicMetaObject errorSuggestion)
        {
            DynamicMetaObject left = target;
            DynamicMetaObject right = arg;

            if (Operation != ExpressionType.LessThan)
                throw new NotImplementedException();

            if (left.LimitType != right.LimitType)
            {
                throw new Exception(String.Format(
                    "attempt to compare {0} with {1}",
                    left.LimitType.Name, right.LimitType.Name));
            }

            if (left.LimitType != typeof(string) &&
                left.LimitType != typeof(double))
            {
                throw new Exception(String.Format(
                    "attempt to compare two {0} values",
                    left.LimitType.Name));
            }

            return _binder.DoOperation(Operation, left, right);
        }
开发者ID:fgretief,项目名称:IronLua,代码行数:28,代码来源:MyLanguage.cs


示例8: ComInvokeBinder

        internal ComInvokeBinder(
                CallInfo callInfo, 
                DynamicMetaObject[] args,
                bool[] isByRef,
                BindingRestrictions restrictions, 
                Expression method, 
                Expression dispatch, 
                ComMethodDesc methodDesc
                ) {

            Debug.Assert(callInfo != null, "arguments");
            Debug.Assert(args != null, "args");
            Debug.Assert(isByRef != null, "isByRef");
            Debug.Assert(method != null, "method");
            Debug.Assert(dispatch != null, "dispatch");

            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(ComMethodDesc), method.Type), "method");
            Debug.Assert(TypeUtils.AreReferenceAssignable(typeof(IDispatch), dispatch.Type), "dispatch");

            _method = method;
            _dispatch = dispatch;
            _methodDesc = methodDesc;

            _callInfo = callInfo;
            _args = args;
            _isByRef = isByRef;
            _restrictions = restrictions;

            // Set Instance to some value so that CallBinderHelper has the right number of parameters to work with
            _instance = dispatch;
        }
开发者ID:KonajuGames,项目名称:SharpLang,代码行数:31,代码来源:ComInvokeBinder.cs


示例9: MakeStandardDotNetTypeCall

        /// <summary>
        /// Creating a standard .NET type is easy - we just call it's constructor with the provided
        /// arguments.
        /// </summary>
        private DynamicMetaObject/*!*/ MakeStandardDotNetTypeCall(DynamicMetaObjectBinder/*!*/ call, Expression/*!*/ codeContext, DynamicMetaObject/*!*/[]/*!*/ args) {
            CallSignature signature = BindingHelpers.GetCallSignature(call);
            BinderState state = BinderState.GetBinderState(call);
            MethodBase[] ctors = CompilerHelpers.GetConstructors(Value.UnderlyingSystemType, state.Binder.PrivateBinding);

            if (ctors.Length > 0) {
                return state.Binder.CallMethod(
                    new ParameterBinderWithCodeContext(state.Binder, codeContext),
                    ctors,
                    args,
                    signature,
                    Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
                );
            } else {
                return new DynamicMetaObject(
                   Ast.Throw(
                       Ast.New(
                           typeof(ArgumentTypeException).GetConstructor(new Type[] { typeof(string) }),
                           Ast.Constant("Cannot create instances of " + Value.Name)
                       )
                   ),
                   Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression, Value))
                );
            }
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:29,代码来源:MetaPythonType.Calls.cs


示例10: FallbackDeleteMember

        public override DynamicMetaObject FallbackDeleteMember(DynamicMetaObject self, DynamicMetaObject errorSuggestion) {
            if (self.NeedsDeferral()) {
                return Defer(self);
            }

            return Binder.Binder.DeleteMember(Name, self, AstUtils.Constant(Binder.Context));
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:7,代码来源:PythonDeleteMemberBinder.cs


示例11: TryBind

        public static DynamicMetaObject TryBind(RubyContext/*!*/ context, GetMemberBinder/*!*/ binder, DynamicMetaObject/*!*/ target) {
            Assert.NotNull(context, target);
            var metaBuilder = new MetaObjectBuilder();
            var contextExpression = AstUtils.Constant(context);

            RubyClass targetClass = context.GetImmediateClassOf(target.Value);
            MethodResolutionResult method;
            RubyMemberInfo methodMissing = null;

            using (targetClass.Context.ClassHierarchyLocker()) {
                metaBuilder.AddTargetTypeTest(target.Value, targetClass, target.Expression, context, contextExpression);

                method = targetClass.ResolveMethodForSiteNoLock(binder.Name, RubyClass.IgnoreVisibility);
                if (method.Found) {
                    methodMissing = targetClass.ResolveMethodForSiteNoLock(Symbols.MethodMissing, RubyClass.IgnoreVisibility).Info;
                }
            }
            
            if (method.Found) {
                // we need to create a bound member:
                metaBuilder.Result = AstUtils.Constant(new RubyMethod(target.Value, method.Info, binder.Name));
            } else {
                // TODO:
                // We need to throw an exception if we don't find method_missing so that our version update optimization works: 
                // This limits interop with other languages. 
                //                   
                // class B           CLR type with method 'foo'
                // class C < B       Ruby class
                // x = C.new
                //
                // 1. x.GET("foo") from Ruby
                //    No method found or CLR method found -> fallback to Python
                //    Python might see its method foo or might just fallback to .NET, 
                //    in any case it will add rule [1] with restriction on type of C w/o Ruby version check.
                // 2. B.define_method("foo") 
                //    This doesn't update C due to the optimization (there is no overridden method foo in C).
                // 3. x.GET("foo") from Ruby
                //    This will not invoke the binder since the rule [1] is still valid.
                //
                object symbol = SymbolTable.StringToId(binder.Name);
                RubyCallAction.BindToMethodMissing(metaBuilder, 
                    new CallArguments(
                        new DynamicMetaObject(contextExpression, BindingRestrictions.Empty, context),
                        new[] { 
                            target,
                            new DynamicMetaObject(AstUtils.Constant(symbol), BindingRestrictions.Empty, symbol) 
                        },
                        RubyCallSignature.Simple(1)
                    ),
                    binder.Name,
                    methodMissing,
                    method.IncompatibleVisibility,
                    false
                );
            }

            // TODO: we should return null if we fail, we need to throw exception for now:
            return metaBuilder.CreateMetaObject(binder, DynamicMetaObject.EmptyMetaObjects);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:59,代码来源:RubyGetMemberBinder.cs


示例12: Invoke

        public DynamicMetaObject/*!*/ Invoke(PythonInvokeBinder/*!*/ pythonInvoke, Expression/*!*/ codeContext, DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args) {
            DynamicMetaObject translated = BuiltinFunction.TranslateArguments(pythonInvoke, codeContext, target, args, false, Value.Name);
            if (translated != null) {
                return translated;
            }

            return InvokeWorker(pythonInvoke, args, codeContext);
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:8,代码来源:MetaPythonType.Calls.cs


示例13: FallbackInvokeMember

        public override DynamicMetaObject/*!*/ FallbackInvokeMember(DynamicMetaObject/*!*/ self, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject/*!*/ onBindingError) {
            var result = TryBind(_context, this, self, args);
            if (result != null) {
                return result;
            }

            // TODO: return ((DefaultBinder)_context.Binder).GetMember(Name, self, Ast.Null(typeof(CodeContext)), true);
            throw new NotImplementedException();
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:RubyInvokeMemberBinder.cs


示例14: FallbackGetMember

        public override DynamicMetaObject/*!*/ FallbackGetMember(DynamicMetaObject/*!*/ self, DynamicMetaObject/*!*/ onBindingError) {
            var result = TryBind(_context, this, self);
            if (result != null) {
                return result; 
            }

            // TODO: remove CodeContext
            return ((DefaultBinder)_context.Binder).GetMember(Name, self, AstUtils.Constant(null, typeof(CodeContext)), true);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:9,代码来源:RubyGetMemberBinder.cs


示例15: switch

        DynamicMetaObject IPythonOperable.BindOperation(PythonOperationBinder action, DynamicMetaObject[] args) {
            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "BuiltinFunc Operation " + action.Operation);
            PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, "BuiltinFunc Operation");
            switch (action.Operation) {
                case PythonOperationKind.CallSignatures:
                    return PythonProtocol.MakeCallSignatureOperation(this, Value.Targets);
            }

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


示例16: BindOperation

        public override DynamicMetaObject/*!*/ BindOperation(OperationBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            switch (action.Operation) {
                case StandardOperators.CallSignatures:
                    return MakeCallSignatureRule(this);
                case StandardOperators.IsCallable:
                    return MakeIsCallableRule(this);
            }

            return base.BindOperation(action, args);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:10,代码来源:MetaPythonFunction.cs


示例17: FallbackInvoke

 public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion) {
     return new DynamicMetaObject(
         Expression.Call(
             typeof(String).GetMethod("Concat", new Type[] { typeof(object), typeof(object) }),
             Expression.Constant("FallbackInvoke"),
             target.Expression
         ),
         BindingRestrictionsHelpers.GetRuntimeTypeRestriction(target)
     );
 }
开发者ID:jcteague,项目名称:ironruby,代码行数:10,代码来源:DlrInteropTests.cs


示例18: FallbackCreateInstance

        public override DynamicMetaObject/*!*/ FallbackCreateInstance(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args, DynamicMetaObject errorSuggestion) {
            var result = TryBind(_context, this, target, args);
            if (result != null) {
                return result;
            }

            throw new NotImplementedException();
            // TODO:
            //return ((DefaultBinder)_context.Binder).Create(.GetMember(Name, self, Ast.Null(typeof(CodeContext)), true);
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:10,代码来源:RubyCreateInstanceBinder.cs


示例19: Bind

        /// <summary>
        /// Performs the binding of the dynamic set member operation.
        /// </summary>
        /// <param name="target">The target of the dynamic set member operation.</param>
        /// <param name="args">An array of arguments of the dynamic set member operation.</param>
        /// <returns>The <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
        public sealed override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args) {
            ContractUtils.RequiresNotNull(target, "target");
            ContractUtils.RequiresNotNull(args, "args");
            ContractUtils.Requires(args.Length == 1, "args");

            var arg0 = args[0];
            ContractUtils.RequiresNotNull(arg0, "args");

            return target.BindSetMember(this, arg0);
        }
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:16,代码来源:SetMemberBinder.cs


示例20: Bind

        /// <summary>
        /// Python's Invoke is a non-standard action.  Here we first try to bind through a Python
        /// internal interface (IPythonInvokable) which supports CallSigantures.  If that fails
        /// and we have an IDO then we translate to the DLR protocol through a nested dynamic site -
        /// this includes unsplatting any keyword / position arguments.  Finally if it's just a plain
        /// old .NET type we use the default binder which supports CallSignatures.
        /// </summary>
        public override DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ target, DynamicMetaObject/*!*/[]/*!*/ args) {
            Debug.Assert(args.Length > 0);

            DynamicMetaObject cc = target;
            DynamicMetaObject actualTarget = args[0];
            args = ArrayUtils.RemoveFirst(args);

            Debug.Assert(cc.GetLimitType() == typeof(CodeContext));

            return BindWorker(cc, actualTarget, args);
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:18,代码来源:PythonInvokeBinder.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# DynamicMetaObjectBinder类代码示例发布时间:2022-05-24
下一篇:
C# DynamicList类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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