Пример #1
0
        public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            DynamicMetaObject messageSendMO;
            var    esClass = ValueClass;
            var    kernel  = esClass.ObjectSpace;
            long   numArgs = args.Length;
            String selector;

            switch (numArgs)
            {
            case 0:
                selector = "new";
                break;

            case 1:
                if (createMetaObjectToSendMessage("new:", argArrayFor(args), out messageSendMO))
                {
                    return(messageSendMO);
                }
                selector = "value:";
                break;

            default:
                selector = kernel.selectorToEvaluatBlockWithNumArgs(numArgs).PrimitiveValue;
                break;
            }
            if (createMetaObjectToSendMessage(selector, argArrayFor(args), out messageSendMO))
            {
                return(messageSendMO);
            }
            return(binder.FallbackCreateInstance(this, args, metaObjectToSendDoesNotUnderstand(kernel.symbolFor(selector), args)));
        }
 public override DynamicMetaObject BindCreateInstance(
     CreateInstanceBinder binder,
     DynamicMetaObject[] args
     )
 {
     return(IsOverridden(nameof(DynamicProxy <T> .TryCreateInstance))
       ? CallMethodWithResult(
                nameof(DynamicProxy <T> .TryCreateInstance),
                binder,
                GetArgArray(args),
                e => binder.FallbackCreateInstance(this, args, e)
                )
       : base.BindCreateInstance(binder, args));
 }
Пример #3
0
        public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            var constructors = ReflectedType.GetConstructors();
            var res          = Array.FindAll(constructors, c => c.GetParameters().Length == args.Length && RuntimeHelpers.ParametersMatchArguments(c.GetParameters(), args));

            if (res.Length == 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));
        }
Пример #4
0
        public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            var      esClass = ValueClass;
            var      kernel  = esClass.ObjectSpace;
            long     numArgs = args.Length;
            ESSymbol selector;

            switch (numArgs)
            {
            case 0:
                selector = kernel.symbolFor("new");
                break;

            case 1:
                selector = kernel.symbolFor("new:");
                break;

            default:
                selector = kernel.selectorToEvaluatBlockWithNumArgs(numArgs);
                break;
            }
            return(binder.FallbackCreateInstance(this, args, metaObjectToSendDoesNotUnderstand(selector, args)));
        }
Пример #5
0
        public override DynamicMetaObject BindCreateInstance(
            CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            var constructors = ReflType.GetConstructors();
            var ctors        = constructors.
                               Where(c => c.GetParameters().Length == args.Length);
            List <ConstructorInfo> 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));
        }
Пример #6
0
        public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            if (IsOverridden("TryCreateInstance"))
            {
                return(CallMethodWithResult("TryCreateInstance", binder, GetExpressions(args), (e) => binder.FallbackCreateInstance(this, args, e)));
            }

            return(base.BindCreateInstance(binder, args));
        }
Пример #7
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     return(_runtime.TryCreateInstance != null
          ? CallMethodWithResult("TryCreateInstance", binder, GetArgArray(args), e => binder.FallbackCreateInstance(this, args, e))
          : base.BindCreateInstance(binder, args));
 }
Пример #8
0
 public override DynamicMetaObject _0001(CreateInstanceBinder config, DynamicMetaObject[] pol)
 {
     //Discarded unreachable code: IL_0002
     //IL_0003: Incompatible stack heights: 0 vs 1
     if (!CancelProperty("TryCreateInstance"))
     {
         return(base.BindCreateInstance(config, pol));
     }
     return(DefineProperty("TryCreateInstance", config, WorkerClientBridge <T> ._0001(pol), (DynamicMetaObject P_0) => config.FallbackCreateInstance(this, pol, P_0)));
 }
            public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) {
                if (IsOverridden("TryCreateInstance")) {
                    return CallMethodWithResult("TryCreateInstance", binder, GetArgArray(args), (e) => binder.FallbackCreateInstance(this, args, e));
                }

                return base.BindCreateInstance(binder, args);
            }
 /// <summary>
 /// Performs the binding of the dynamic create instance operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="CreateInstanceBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the create instance operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackCreateInstance(this, args);
 }
Пример #11
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     if (!this.IsOverridden("TryCreateInstance"))
     {
         return(base.BindCreateInstance(binder, args));
     }
     return(this.CallMethodWithResult("TryCreateInstance", binder, DynamicProxyMetaObject <T> .GetArgArray(args), (DynamicMetaObject e) => binder.FallbackCreateInstance(this, args, e), null));
 }
Пример #12
0
 /// <summary>
 /// Performs the binding of the dynamic create instance operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="CreateInstanceBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the create instance operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackCreateInstance(this, args));
 }
Пример #13
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     return(binder.FallbackCreateInstance(_baseMetaObject,
                                          args,
                                          AddTypeRestrictions(_metaObject.BindCreateInstance(binder, args))));
 }