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

C# Dynamic.DynamicMetaObject类代码示例

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

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



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

示例1: 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.RequiresNotNullItems(args, "args");
            ContractUtils.Requires(args.Length == 1);

            return target.BindSetMember(this, args[0]);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:13,代码来源:SetMemberBinder.cs


示例2: Bind

        /// <summary>
        /// Performs the binding of the dynamic operation.
        /// </summary>
        /// <param name="target">The target of the dynamic operation.</param>
        /// <param name="args">An array of arguments of the dynamic operation.</param>
        /// <returns>The System.Dynamic.DynamicMetaObject representing the result of the binding.</returns>
        public override DynamicMetaObject Bind(DynamicMetaObject target, DynamicMetaObject[] args)
        {
            #if DEBUG
            if ((args == null) || (args.Length != 2))
                throw new InvalidOperationException("The DoesNotUnderstandCallSiteBinder is special case and always requires 2 method arguments.");
            #endif
            // Look-up the #_doesNotUnderstand:arguments: method.
            BindingRestrictions restrictions;
            SmalltalkClass receiverClass;
            Expression expression;
            MethodLookupHelper.GetMethodInformation(this.Runtime,
                this.Runtime.GetSymbol("_doesNotUnderstand:arguments:"),
                null,
                target.Value,
                target,
                args,
                out receiverClass,
                out restrictions,
                out expression);

            // Every class is supposed to implement the #_doesNotUnderstand:arguments:, if not, throw a runtime exception
            if (expression == null)
                throw new RuntimeCodeGenerationException(RuntimeCodeGenerationErrors.DoesNotUnderstandMissing);

            // Perform a standard cal to the #_doesNotUnderstand:arguments:
            return new DynamicMetaObject(expression, target.Restrictions.Merge(restrictions));
        }
开发者ID:erlis,项目名称:IronSmalltalk,代码行数:33,代码来源:DoesNotUnderstandCallSiteBinder.cs


示例3: 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:jxnmaomao,项目名称:ironruby,代码行数:25,代码来源:ComBinder.cs


示例4: Bind

        /// <summary>
        /// Performs the binding of the dynamic delete index operation.
        /// </summary>
        /// <param name="target">The target of the dynamic delete index operation.</param>
        /// <param name="args">An array of arguments of the dynamic delete index 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, nameof(target));
            ContractUtils.RequiresNotNullItems(args, nameof(args));

            return target.BindDeleteIndex(this, args);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:DeleteIndexBinder.cs


示例5: RuntimeValueExpression

		public RuntimeValueExpression (DynamicMetaObject obj, bool typed)
		{
			this.obj = obj;
			this.typed = typed;
			this.type = obj.RuntimeType;
			this.eclass = ExprClass.Value;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:dynamic.cs


示例6: ToExpressions

 // negative start reserves as many slots at the beginning of the new array:
 internal static Expression/*!*/[]/*!*/ ToExpressions(DynamicMetaObject/*!*/[]/*!*/ args, int start) {
     var result = new Expression[args.Length - start];
     for (int i = Math.Max(0, -start); i < result.Length; i++) {
         result[i] = args[start + i].Expression;
     }
     return result;
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:8,代码来源:RubyBinder.cs


示例7: ConvertTo

        public DynamicMetaObject ConvertTo(Type toType, ConversionResultKind kind, DynamicMetaObject arg, OverloadResolverFactory resolverFactory, DynamicMetaObject errorSuggestion) {
            ContractUtils.RequiresNotNull(toType, "toType");
            ContractUtils.RequiresNotNull(arg, "arg");

            Type knownType = arg.GetLimitType();

            // try all the conversions - first look for conversions against the expression type,
            // these can be done w/o any additional tests.  Then look for conversions against the 
            // restricted type.
            BindingRestrictions typeRestrictions = arg.Restrictions.Merge(BindingRestrictionsHelpers.GetRuntimeTypeRestriction(arg.Expression, arg.GetLimitType()));

            DynamicMetaObject res = 
                TryConvertToObject(toType, arg.Expression.Type, arg, typeRestrictions) ??
                TryAllConversions(resolverFactory, toType, kind, arg.Expression.Type, typeRestrictions, arg) ??
                TryAllConversions(resolverFactory, toType, kind, arg.GetLimitType(), typeRestrictions, arg) ??
                errorSuggestion ??
                MakeErrorTarget(toType, kind, typeRestrictions, arg);

            if ((kind == ConversionResultKind.ExplicitTry || kind == ConversionResultKind.ImplicitTry) && toType.IsValueType) {
                res = new DynamicMetaObject(
                    AstUtils.Convert(
                        res.Expression,
                        typeof(object)
                    ),
                    res.Restrictions
                );
            }
            return res;
        }
开发者ID:BenHall,项目名称:ironruby,代码行数:29,代码来源:DefaultBinder.Conversions.cs


示例8: GetArguments

        private DynamicMetaObject[] GetArguments(DynamicMetaObject[] args, IList<DynamicMetaObject> results, int metaBinderIndex) {
            BinderMappingInfo indices = _metaBinders[metaBinderIndex];

            DynamicMetaObject[] res = new DynamicMetaObject[indices.MappingInfo.Count];
            for (int i = 0; i < res.Length; i++) {
                ParameterMappingInfo mappingInfo = indices.MappingInfo[i];

                if (mappingInfo.IsAction) {
                    // input is the result of a previous bind
                    res[i] = results[mappingInfo.ActionIndex];
                } else if (mappingInfo.IsParameter) {
                    // input is one of the original arguments
                    res[i] = args[mappingInfo.ParameterIndex];
                } else {
                    // input is a constant
                    res[i] = new DynamicMetaObject(
                        mappingInfo.Constant,
                        BindingRestrictions.Empty,
                        mappingInfo.Constant.Value
                    );
                }
            }

            return res;
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:25,代码来源:ComboBinder.cs


示例9: PythonOverloadResolver

 // instance method call:
 public PythonOverloadResolver(PythonBinder binder, DynamicMetaObject instance, IList<DynamicMetaObject> args, CallSignature signature,
     Expression codeContext)
     : base(binder, instance, args, signature)
 {
     Assert.NotNull(codeContext);
     _context = codeContext;
 }
开发者ID:TerabyteX,项目名称:main,代码行数:8,代码来源:PythonOverloadResolver.cs


示例10: FallbackSetMember

 /// <summary>
 /// Performs the binding of the dynamic set member operation if the target dynamic object
 ///  cannot bind.
 /// </summary>
 /// <param name="target">The target of the dynamic set member operation.</param>
 /// <param name="value">The value to set to the member.</param>
 /// <param name="errorSuggestion">The binding result to use if binding fails, or null.
 /// </param>
 /// <returns>
 /// The <see cref="T:System.Dynamic.DynamicMetaObject"/> representing the result of the
 /// binding.
 /// </returns>
 public override DynamicMetaObject FallbackSetMember(
     DynamicMetaObject target,
     DynamicMetaObject value,
     DynamicMetaObject errorSuggestion)
 {
     return null;
 }
开发者ID:kerryjiang,项目名称:DynamicViewModel,代码行数:19,代码来源:SetBinder.cs


示例11: Create

        public DynamicMetaObject Create(CallSignature signature, DynamicMetaObject target, DynamicMetaObject[] args, Expression contextExpression) {

            Type t = GetTargetType(target.Value);

            if (t != null) {

                if (typeof(Delegate).IsAssignableFrom(t) && args.Length == 1) {
                    // PythonOps.GetDelegate(CodeContext context, object callable, Type t);
                    return new DynamicMetaObject(
                        Ast.Call(
                            typeof(PythonOps).GetMethod("GetDelegate"),
                            contextExpression,
                            AstUtils.Convert(args[0].Expression, typeof(object)),
                            Expression.Constant(t)
                        ),
                        target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value))
                    );
                }

                return CallMethod(
                    new PythonOverloadResolver(
                        this,
                        args,
                        signature,
                        contextExpression
                    ),
                    CompilerHelpers.GetConstructors(t, PrivateBinding),
                    target.Restrictions.Merge(BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value))
                );
            }

            return null;
        }
开发者ID:rudimk,项目名称:dlr-dotnet,代码行数:33,代码来源:PythonBinder.Create.cs


示例12: Call

        internal static DynamicMetaObject Call(DynamicMetaObjectBinder call, DynamicMetaObject target, DynamicMetaObject[] args)
        {
            Assert.NotNull(call, args);
            Assert.NotNullItems(args);

            if (target.NeedsDeferral())
                return call.Defer(ArrayUtils.Insert(target, args));

            foreach (var mo in args)
            {
                if (mo.NeedsDeferral())
                {
                    RestrictTypes(args);

                    return call.Defer(
                        ArrayUtils.Insert(target, args)
                    );
                }
            }

            DynamicMetaObject self = target.Restrict(target.GetLimitType());

            ValidationInfo valInfo = BindingHelpers.GetValidationInfo(target);
            TotemType tt = DynamicHelpers.GetTotemType(target.Value);
            TotemContext toContext = GetTotemContext(call);

            throw new NotImplementedException();
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:28,代码来源:TotemProtocol.cs


示例13: ConvertToString

        internal static DynamicMetaObject ConvertToString(DynamicMetaObjectBinder conversion, DynamicMetaObject self)
        {
            Assert.NotNull(conversion, self);

            TotemType ltype = MetaTotemObject.GetTotemType(self);
            var matches = ltype.GetOperatorFunctions(TotemOperationKind.ToString).ToList();

            var overloadResolver = GetTotemContext(conversion).SharedOverloadResolverFactory.CreateOverloadResolver(new[] { self }, new CallSignature(1), CallTypes.None);
            var ret = overloadResolver.ResolveOverload("ToString", ArrayUtils.ToArray(matches, m => CreateOverloadInfo(m)), NarrowingLevel.None, NarrowingLevel.All);

            if (!ret.Success)
            {
                return new DynamicMetaObject(
                    Expression.Throw(
                        Expression.Call(
                            AstMethods.TypeError,
                            Utils.Constant("No toString found on type {1}."),
                            Expression.NewArrayInit(
                                typeof(string),
                                Expression.Constant(ltype.Name)
                            )
                        )
                    ),
                    BindingRestrictions.Combine(new[] { self })
                );
            }
            return new DynamicMetaObject(ret.MakeExpression(), ret.RestrictedArguments.GetAllRestrictions());
        }
开发者ID:Alxandr,项目名称:IronTotem-3.0,代码行数:28,代码来源:TotemProtocol.cs


示例14: FallbackGetMember

        public override DynamicMetaObject FallbackGetMember(DynamicMetaObject targetMO, DynamicMetaObject errorSuggestion)
        {
            // Defer if any object has no value so that we evaulate their
            // Expressions and nest a CallSite for the InvokeMember.
            if (!targetMO.HasValue)
                return Defer(targetMO);

            // Find our own binding.
            MemberInfo[] members = targetMO.LimitType.GetMember(Name, DefaultBindingFlags);
            if (members.Length == 1)
            {
                return new DynamicMetaObject(
                    RuntimeHelpers.EnsureObjectResult(
                        Expression.MakeMemberAccess(
                            Expression.Convert(targetMO.Expression,
                                               members[0].DeclaringType),
                            members[0])),
                    // Don't need restriction test for name since this
                    // rule is only used where binder is used, which is
                    // only used in sites with this binder.Name.
                    BindingRestrictions.GetTypeRestriction(targetMO.Expression,
                                                           targetMO.LimitType));
            }

            return errorSuggestion ??
                   RuntimeHelpers.CreateBindingThrow(
                       targetMO, null,
                       BindingRestrictions.GetTypeRestriction(targetMO.Expression, targetMO.LimitType),
                       typeof(MissingMemberException),
                       "cannot bind member, " + Name + ", on object " + targetMO.Value);
        }
开发者ID:kthompson,项目名称:CoffeeScript,代码行数:31,代码来源:CoffeeScriptGetMemberBinder.cs


示例15: CSharpBinder

		public CSharpBinder (DynamicMetaObjectBinder binder, Compiler.Expression expr, DynamicMetaObject errorSuggestion)
		{
			this.binder = binder;
			this.expr = expr;
			this.restrictions = BindingRestrictions.Empty;
			this.errorSuggestion = errorSuggestion;
		}
开发者ID:bbqchickenrobot,项目名称:playscript-mono,代码行数:7,代码来源:CSharpBinder.cs


示例16: BindBinaryOperationInvalidTest

        public void BindBinaryOperationInvalidTest()
        {
            DynamicMetaObject target;

            DynamicMetaObject argPrimitive = new DynamicMetaObject(Expression.Constant(10), BindingRestrictions.Empty);
            DynamicMetaObject argNonPrimitive = new DynamicMetaObject(Expression.Constant(AnyInstance.AnyJsonObject), BindingRestrictions.Empty);

            foreach (JsonValue value in AnyInstance.AnyJsonValueArray)
            {
                target = GetJsonValueDynamicMetaObject(value);

                TestBinaryOperationBinder.TestMetaObject(target, argPrimitive, TestBinaryOperationBinder.UnsupportedOperations, false);
            }

            foreach (JsonValue value in AnyInstance.AnyJsonValueArray)
            {
                target = GetJsonValueDynamicMetaObject(value);

                if (value is JsonPrimitive)
                {
                    //// not supported on operand of type JsonValue if it isn't a primitive and not comparing JsonValue types.
                    TestBinaryOperationBinder.TestMetaObject(target, argNonPrimitive, TestBinaryOperationBinder.NumberOperations, false);
                    TestBinaryOperationBinder.TestMetaObject(target, argNonPrimitive, TestBinaryOperationBinder.BoolOperations, false);
                }
                else
                {
                    //// When value is non-primitive, it must be a compare operation and (the other operand must be null or a JsonValue)
                    TestBinaryOperationBinder.TestMetaObject(target, argPrimitive, TestBinaryOperationBinder.NumberOperations, false);
                    TestBinaryOperationBinder.TestMetaObject(target, argPrimitive, TestBinaryOperationBinder.BoolOperations, false);
                }
            }
        }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:32,代码来源:JsonValueDynamicMetaObjectTest.cs


示例17: FallbackUnaryOperation

        public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
        {
            const string errorMsg = "{0}を符号反転出来ません。";

            if (target.Value == null) {
                var msg = String.Format(errorMsg, ConstantNames.NullText);
                var ctorInfo = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) });
                var expr = Expression.Throw(Expression.New(ctorInfo, Expression.Constant(errorMsg)), this.ReturnType);
                var rest = BindingRestrictions.GetExpressionRestriction(BinderHelper.IsNull(target.Expression));
                return new DynamicMetaObject(expr, rest);
            }
            try {
                var expr = BinderHelper.Wrap(Expression.Negate(Expression.Convert(target.Expression, target.LimitType)), this.ReturnType);
                var rest = BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType);
                return new DynamicMetaObject(expr, rest);
            }
            catch (InvalidOperationException) {
                var msgExpr = ExpressionHelper.BetaReduction<string, object, string>(
                    (format, obj) => String.Format(format, obj),
                    Expression.Constant(errorMsg), target.Expression);
                var ctorInfo = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) });
                var expr = Expression.Throw(Expression.New(ctorInfo, msgExpr), this.ReturnType);
                var rest = BindingRestrictions.GetTypeRestriction(target.Expression, target.LimitType);
                return new DynamicMetaObject(expr, rest);
            }
        }
开发者ID:irxground,项目名称:kurogane,代码行数:26,代码来源:NegateBinder.cs


示例18: ToValues

 // negative start reserves as many slots at the beginning of the new array:
 internal static object/*!*/[]/*!*/ ToValues(DynamicMetaObject/*!*/[]/*!*/ args, int start) {
     var result = new object[args.Length - start];
     for (int i = Math.Max(0, -start); i < result.Length; i++) {
         result[i] = args[start + i].Value;
     }
     return result;
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:8,代码来源:RubyBinder.cs


示例19: Bind

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

            return target.BindGetMember(this);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:GetMemberBinder.cs


示例20: BindCreateInstance

        public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            var constructors = ReflType.GetConstructors();
            var ctors = constructors.Where(c => c.GetParameters().Length == args.Length);
            var res = new List<ConstructorInfo>();

            foreach (var c in ctors)
            {
                if (RuntimeHelpers.ParametersMatchArguments(c.GetParameters(), args))
                {
                    res.Add(c);
                }
            }
            if (res.Count == 0)
            {
                // Binders won't know what to do with TypeModels, so pass the
                // RuntimeType they represent.  The binder might not be Sympl's.
                return binder.FallbackCreateInstance(
                    RuntimeHelpers.GetRuntimeTypeMoFromModel(this),
                    args);
            }
            // For create instance of a TypeModel, we can create a instance
            // restriction on the MO, hence the true arg.
            var restrictions = RuntimeHelpers.GetTargetArgsRestrictions(this, args, true);
            var ctorArgs = RuntimeHelpers.ConvertArguments(args, res[0].GetParameters());
            return new DynamicMetaObject(
                // Creating an object, so don't need EnsureObjectResult.
                Expression.New(res[0], ctorArgs),
                restrictions);
        }
开发者ID:kthompson,项目名称:CoffeeScript,代码行数:30,代码来源:TypeModelMetaObject.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Dynamic.DynamicMetaObjectBinder类代码示例发布时间:2022-05-26
下一篇:
C# Dynamic.ConvertBinder类代码示例发布时间: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