当前位置: 首页>>代码示例>>C#>>正文


C# Dynamic.DynamicMetaObject类代码示例

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


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


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