Example #1
0
        public virtual object Invoke(string name, object[] parameters)
        {
            object value = this.GetValue(name);

            if (value == null && this.IsNativeMethod(name))
            {
                return(ObjectUtilities.GetNativeValue(this, name, parameters));
            }

            if (value == null)
            {
                throw new InvalidOperationException(string.Format("Unknown member '{0}'", name));
            }

            if (!(value is ICallable))
            {
                if (parameters == null)
                {
                    return(value);
                }

                throw new InvalidOperationException(string.Format("'{0}' is not a method", name));
            }

            ICallable method = (ICallable)value;

            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return(method.Invoke(objenv, parameters));
        }
Example #2
0
 public Object(
     ObjectEnvironment environment,
     string id,
     string name,
     ObjectType type,
     string description = null,
     Object parent = null
     )
     : base(environment, id, name, type, description, parent)
 {
 }
Example #3
0
        public Pwm(
            ObjectEnvironment environment,
            string id,
            string name,
            PwmController controller,
            string description = null,
            Object parent = null
            )
            : base(environment, id, name,
                new ObjectType("PWM", "PWM", "Pulse width modulation"),
                description, parent)
        {
            controller.ValidateNonNull(nameof(controller));
            Controller = controller;

            PinCount = new Property<int>(this, nameof(PinCount), "Pin count", Controller.PinCount);
            Items.Add(PinCount);

            DelegateCommand command;
            command = new DelegateCommand<int>(this,
                nameof(OpenPin), "Open pin",
                p => OpenPin(p),
                p => CanOpenPin(p),
                parameters: new CommandParameterInfo<int>("Number", "Number", "Pin number")
                );
            Items.Add(command);

            Frequency = new PhysicalProperty<double>(this,
                nameof(Frequency), "Frequency", Controller.ActualFrequency, Units.Hertz);
            Items.Add(Frequency);

            MinFrequency = new PhysicalProperty<double>(this,
                nameof(MinFrequency), "Minimum frequency", Controller.MinFrequency, Units.Hertz);
            Items.Add(MinFrequency);

            MaxFrequency = new PhysicalProperty<double>(this,
                nameof(MaxFrequency), "Maximum frequency", Controller.MaxFrequency, Units.Hertz);
            Items.Add(MaxFrequency);

            command = new DelegateCommand<double>(this,
                nameof(SetFrequency), "Set frequency",
                p => SetFrequency(p),
                p => CanSetFrequency(p),
                parameters: new CommandPhysicalParameterInfo<double>(Frequency)
                );
            Items.Add(command);
        }
        public override object Invoke(string name, object[] parameters)
        {
            object value = this.GetValue(name);

            if (value == null || !(value is ICallable))
            {
                value = this.objclass.GetMember(name);
            }

            if (value == null)
            {
                if (this.IsNativeMethod(name))
                {
                    return(ObjectUtilities.GetNativeValue(this, name, parameters));
                }

                if (this.objclass.DefaultMember != null)
                {
                    ICallable           defmethod = (ICallable)this.objclass.DefaultMember;
                    IBindingEnvironment oenv      = new ObjectEnvironment(this, defmethod.Environment);
                    object[]            arguments = new object[] { name, parameters };
                    return(defmethod.Invoke(oenv, arguments));
                }
                else
                {
                    return(base.Invoke(name, parameters));
                }
            }

            if (!(value is ICallable))
            {
                if (parameters == null)
                {
                    return(value);
                }

                throw new InvalidOperationException(string.Format("'{0}' is not a method", name));
            }

            ICallable method = (ICallable)value;

            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return(method.Invoke(objenv, parameters));
        }
Example #5
0
        public override object Invoke(string name, object[] parameters)
        {
            object value = this.GetValue(name);

            if (value == null || !(value is ICallable))
                value = this.objclass.GetMember(name);

            if (value == null)
            {
                if (this.IsNativeMethod(name))
                    return ObjectUtilities.GetNativeValue(this, name, parameters);

                if (this.objclass.DefaultMember != null)
                {
                    ICallable defmethod = (ICallable)this.objclass.DefaultMember;
                    IBindingEnvironment oenv = new ObjectEnvironment(this, defmethod.Environment);
                    object[] arguments = new object[] { name, parameters };
                    return defmethod.Invoke(oenv, arguments);
                }
                else
                    return base.Invoke(name, parameters);
            }

            if (!(value is ICallable))
            {
                if (parameters == null)
                    return value;

                throw new InvalidOperationException(string.Format("'{0}' is not a method", name));
            }

            ICallable method = (ICallable)value;

            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return method.Invoke(objenv, parameters);
        }
Example #6
0
        public virtual object Invoke(string name, object[] parameters)
        {
            object value = this.GetValue(name);

            if (value == null && this.IsNativeMethod(name))
                return ObjectUtilities.GetNativeValue(this, name, parameters);

            if (value == null)
                throw new InvalidOperationException(string.Format("Unknown member '{0}'", name));

            if (!(value is ICallable))
            {
                if (parameters == null)
                    return value;

                throw new InvalidOperationException(string.Format("'{0}' is not a method", name));
            }

            ICallable method = (ICallable)value;

            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return method.Invoke(objenv, parameters);
        }
 public override void ChangeEnvironment(ObjectEnvironment pEnvironment)
 {
 }
Example #8
0
        public virtual object Invoke(ICallable method, object[] parameters)
        {
            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return(method.Invoke(objenv, parameters));
        }
Example #9
0
		/// <summary>
		/// 目前只处理正常陆地环境下的状态,以后有其它状态(比如:骑乘)再添加
		/// </summary>
		/// <param name="pEnvironment"></param>
		public void ChangeEnvironment(ObjectEnvironment pEnvironment)
		{
			_stateController.ChangeEnvironment(pEnvironment);
		}
Example #10
0
        public virtual object Invoke(ICallable method, object[] parameters)
        {
            IBindingEnvironment objenv = new ObjectEnvironment(this, method.Environment);

            return method.Invoke(objenv, parameters);
        }
Example #11
0
 public void SetUp()
 {
     this.dynobj      = new DynamicObject();
     this.environment = new ObjectEnvironment(dynobj);
 }
Example #12
0
 public void SetUp()
 {
     this.dynobj = new DynamicObject();
     this.environment = new ObjectEnvironment(this.dynobj);
 }
Example #13
0
 public abstract void ChangeEnvironment(ObjectEnvironment pEnvironment);