Inheritance: DynamicMetaObjectBinder
Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
		public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
		{
			//--- Debbuger Break --- //
			if(System.Diagnostics.Debugger.IsAttached)
				System.Diagnostics.Debugger.Break();
			//--- Debbuger Break --- //

			return base.TryCreateInstance(binder, args, out result);
		}
Ejemplo n.º 3
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) {
     return new DynamicMetaObject(
         Expression.Call(
             AstUtils.Convert(Expression, typeof(ComTypeClassDesc)),
             typeof(ComTypeClassDesc).GetMethod("CreateInstance")
         ),
         BindingRestrictions.Combine(args).Merge(
             BindingRestrictions.GetTypeRestriction(Expression, typeof(ComTypeClassDesc))
         )
     );
 }
Ejemplo n.º 4
0
 public override Meta BindCreateInstance(CreateInstanceBinder binder, Meta[] args)
 {
     return new Meta(
         Et.Call(
             EtUtils.Cast<IConstructor>(
                 this.Expression
             ),
             IConstructorMethods.MiConstruct,
             AstUtils.NewArrayHelper(
                 typeof(object),
                 DynamicUtils.GetExpressions(args)
             )
         ),
         RestrictUtils.BuildCallRestrictions(
             this,
             args,
             RestrictFlag.Type
         )
     );
 }
Ejemplo n.º 5
0
 public override DynamicMetaObject/*!*/ BindCreateInstance(CreateInstanceBinder/*!*/ binder, DynamicMetaObject/*!*/[]/*!*/ args) {
     return InteropBinder.InvokeMember.Bind(CreateMetaContext(), binder, this, args, binder.FallbackCreateInstance);
 }
Ejemplo n.º 6
0
        public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
        {
            var e = GetEngine();
            var c = e.Converter;
            result = Construct(args.Select(a => c.FromObject(a)));

            return true;
        }
Ejemplo n.º 7
0
 public virtual Object CreateInstance(CreateInstanceBinder binder, Object[] args){ throw Fallback(); }
		public virtual bool TryCreateInstance (CreateInstanceBinder binder, object [] args, out object result)
		{
			Console.WriteLine ("System.Windows.Interop.ComAutomationMetaObjectProviderBase.TryCreateInstance: NIEX");
			throw new NotImplementedException ();
		}
Ejemplo n.º 9
0
            public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args) {
                if (IsOverridden("TryCreateInstance")) {
                    return CallMethodWithResult("TryCreateInstance", binder, DynamicMetaObject.GetExpressions(args), (e) => binder.FallbackCreateInstance(this, args, e));
                }

                return base.BindCreateInstance(binder, args);
            }
Ejemplo n.º 10
0
 public virtual DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     return base.BindCreateInstance(binder, args);
 }
        public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
        {
            if (args.Length > 0)
            {
                result = string.Join(" ", args);
                return true;
            }

            return base.TryCreateInstance(binder, args, out result);
        }
Ejemplo n.º 13
0
 public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
 {
     output.Write("TryCreateInstance");
     return baseElement.TryCreateInstance(binder, args, out result);
 }
Ejemplo n.º 14
0
 //
 // Summary:
 //     Provides the implementation for operations that initialize a new instance of
 //     a dynamic object. This method is not intended for use in C# or Visual Basic.
 //
 // Parameters:
 //   binder:
 //     Provides information about the initialization operation.
 //
 //   args:
 //     The arguments that are passed to the object during initialization. For example,
 //     for the new SampleType(100) operation, where SampleType is the type derived from
 //     the System.Dynamic.DynamicObject class, args[0] is equal to 100.
 //
 //   result:
 //     The result of the initialization.
 //
 // Returns:
 //     true if the operation is successful; otherwise, false. If this method returns
 //     false, the run-time binder of the language determines the behavior. (In most
 //     cases, a language-specific run-time exception is thrown.)
 public virtual bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result);
Ejemplo n.º 15
0
 public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
 {
     return base.TryCreateInstance(binder, args, out result);
 }
    public virtual new bool TryCreateInstance(CreateInstanceBinder binder, Object[] args, out Object result)
    {
      result = default(Object);

      return default(bool);
    }
Ejemplo n.º 17
0
 /// <summary>
 ///     Performs the binding of the dynamic create instance operation.
 /// </summary>
 /// <param name="binder">
 ///     An instance of the <see cref="T:System.Dynamic.CreateInstanceBinder" /> that represents the details of the dynamic operation.
 /// </param>
 /// <param name="args">
 ///     An array of <see cref="T:System.Dynamic.DynamicMetaObject" /> instances - arguments to the create instance operation.
 /// </param>
 /// <returns>
 ///     The new <see cref="T:System.Dynamic.DynamicMetaObject" /> representing the result of the binding.
 /// </returns>
 public override DynamicMetaObject BindCreateInstance( CreateInstanceBinder binder, DynamicMetaObject[] args )
 {
     return ApplyBinding( meta => meta.BindCreateInstance( binder, args ),
                          ( target, errorSuggestion ) =>
                          binder.FallbackCreateInstance( target, args, errorSuggestion ) );
 }
        public virtual new bool TryCreateInstance(CreateInstanceBinder binder, Object[] args, out Object result)
        {
            result = default(Object);

            return(default(bool));
        }
Ejemplo n.º 19
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, nameof(binder));
     return(binder.FallbackCreateInstance(this, args));
 }
Ejemplo n.º 20
0
        public sealed override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
        {
            var fallback = ((Func<Expression>)(() =>
            {
                try { return base.BindCreateInstance(binder, args).Expression; }
                catch (Exception ex) { return Expression.Throw(Expression.Constant(ex)); }
            }))();

            var dispatchResult = Expression.Parameter(typeof(DispatchResult), "dispatchResult");
            var shim = Expression.Block(dispatchResult.MkArray(),
                // 1. var dispatchResult = DispatchCreateInstance(binder, `expression`, args);
                Expression.Assign(dispatchResult, Expression.Call(
                    Expression.Constant(this),
                    typeof(SimpleMetaObject).GetMethod("DispatchCreateInstance", BF.PrivateInstance),
                    Expression.Constant(binder),
                    Expression,
                    Expression.NewArrayInit(typeof(Object), args.Select(arg => Expression.Convert(arg.Expression, typeof(Object)))))),
                // 2. return dispatchResult.Success ? dispatchResult.Result : `fallback`;
                Expression.Condition(
                    Expression.Property(dispatchResult, "Success"),
                    Expression.Convert(Expression.Property(dispatchResult, "Result"), binder.ReturnType),
                    fallback,
                    binder.ReturnType));
            return new DynamicMetaObject(shim, BindingRestrictions.GetTypeRestriction(Expression, LimitType));
        }
Ejemplo n.º 21
0
 public virtual bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
 {
     result = null;
     return(false);
 }
Ejemplo n.º 22
0
        private DispatchResult DispatchCreateInstance(CreateInstanceBinder binder, Object target, Object[] args)
        {
            var old_value = Value;
            Value = target;

            try
            {
                try
                {
                    try
                    {
                        var result = CreateInstance(binder, args);
                        if (result is FallbackException) throw (FallbackException)result;
                        return Succeed(result);
                    }
                    catch (FallbackException)
                    {
                        var dynamic_object = Value as IDynamicObject;
                        if (dynamic_object != null) return Succeed(dynamic_object.CreateInstance(binder, args));
                        else throw;
                    }
                }
                catch (FallbackException)
                {
                    return Fail();
                }
                catch (Exception ex)
                {
                    if (WrapExceptions)
                    {
                        var bind_args = new OrderedDictionary<String, Object>();
                        bind_args.Add("target", target);
                        bind_args.Add("args", args);
                        throw new BindException(binder, bind_args, ex);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                Value = old_value;
            }
        }
Ejemplo n.º 23
0
 public override bool TryCreateInstance(CreateInstanceBinder binder,
                                        object[] args, out object result) {
   try {
     result = this.create(args);
   } catch (ReflectionException) {
     result = null;
     return false;
   } catch (Exception e) {
     throw e;
   }
   return true;
 }
Ejemplo n.º 24
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     return scriptItem.PostProcessBindResult(metaDynamic.BindCreateInstance(binder, args));
 }
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     Fallback fallback = null;
     if (!this.IsOverridden("TryCreateInstance"))
     {
         return base.BindCreateInstance(binder, args);
     }
     if (fallback == null)
     {
         fallback = e => binder.FallbackCreateInstance(this, args, e);
     }
     return this.CallMethodWithResult("TryCreateInstance", binder, GetArgArray(args), fallback);
 }
Ejemplo n.º 26
0
 public override Boolean TryCreateInstance(CreateInstanceBinder binder, Object[] args, out Object result)
 {
     throw new NotImplementedException("TryCreateInstance");
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Provides the implementation of creating an instance of the <see cref="DynamicObject"/>.
 /// Derived classes can override this method to customize behavior.  When not overridden the
 /// call site requesting the binder determines the behavior.
 /// </summary>
 /// <param name="binder">The binder provided by the call site.</param>
 /// <param name="args">The arguments used for creation.</param>
 /// <param name="result">The created instance.</param>
 /// <returns>true if the operation is complete, false if the call site should determine behavior.</returns>
 public virtual bool TryCreateInstance(CreateInstanceBinder binder, object?[]?args, [NotNullWhen(true)] out object?result)
 {
     result = null;
     return(false);
 }
Ejemplo n.º 28
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);
 }
Ejemplo n.º 29
0
 public override bool TryCreateInstance( CreateInstanceBinder binder, object[] args, out object result )
 {
     if(!ReferenceEquals(Prototype, null))
     {
         if(Prototype.TryCreateInstance(binder, args, out result))
         {
             return true;
         }
     }
     if ( TryCreateInstanceMissing == null )
     {
         result = null;
         return false;
     }
     return TryCreateInstanceMissing( binder, args, out result );
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Override on DynamicObject
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="args"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
 {
     result = new Mimic();
     return true;
 }
Ejemplo n.º 31
0
 public override bool TryCreateInstance( CreateInstanceBinder binder, object[] args, out object result )
 {
     if ( TryCreateInstanceMissing == null )
     {
         result = null;
         return false;
     }
     return TryCreateInstanceMissing( binder, args, out result );
 }
Ejemplo n.º 32
0
 public override DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, DynamicMetaObject[] args)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 33
0
 public override bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result)
 {
     MessageBox.Show("Here");
     return base.TryCreateInstance(binder, args, out result);
 }
Ejemplo n.º 34
0
 public virtual bool TryCreateInstance(CreateInstanceBinder binder, object[] args, out object result) {
     result = null;
     return false;
 }
    public virtual new System.Dynamic.DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, System.Dynamic.DynamicMetaObject[] args)
    {
      Contract.Requires(binder != null);

      return default(System.Dynamic.DynamicMetaObject);
    }
Ejemplo n.º 36
0
 public static DynamicMetaObject/*!*/ Bind(DynamicMetaObject/*!*/ context, CreateInstanceBinder/*!*/ binder, DynamicMetaObject/*!*/ target,
     DynamicMetaObject/*!*/[]/*!*/ args, Func<DynamicMetaObject, DynamicMetaObject[], DynamicMetaObject>/*!*/ fallback) {
     return Bind(context, "new", binder.CallInfo, binder, target, args, fallback);
 }
Ejemplo n.º 37
0
        public virtual new System.Dynamic.DynamicMetaObject BindCreateInstance(CreateInstanceBinder binder, System.Dynamic.DynamicMetaObject[] args)
        {
            Contract.Requires(binder != null);

            return(default(System.Dynamic.DynamicMetaObject));
        }