當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。