Пример #1
0
        /// <summary>
        /// Initializes an exception with the specified variable, message, and inner exception
        /// </summary>
        /// <param name="variable">The unbound variable</param>
        /// <param name="message">The message that describes the error</param>
        /// <param name="inner">The exception that is the cause of this exception</param>
        public UnboundVariableException(Variable variable, string message, Exception inner)
            : base(message, inner)
        {
            Contract.Requires(variable != null);

            Variable = variable;
        }
Пример #2
0
        /// <summary>
        /// Initializes a calculation with the specified output variable and expression
        /// </summary>
        /// <param name="outputVariable">The variable to which the output of this calculation is assigned</param>
        /// <param name="expression">The expression tree which defines the body of this calculation</param>
        public Calculation(Variable outputVariable, Expression expression)
        {
            Contract.Requires(outputVariable != null);
            Contract.Requires(expression != null);

            OutputVariable = outputVariable;
            Expression = expression;
        }
Пример #3
0
        /// <summary>
        /// Initializes a function calculator with the specified output variable and function
        /// </summary>
        /// <param name="outputVariable">The variable to which the output of the specified function is assigned</param>
        /// <param name="function">The function which calculates the value to be assigned to the specified output variable</param>
        public FunctionCalculator(Variable outputVariable, Func<GraspRuntime, object> function)
        {
            Contract.Requires(outputVariable != null);
            Contract.Requires(function != null);

            OutputVariable = outputVariable;
            Function = function;
        }
Пример #4
0
        /// <summary>
        /// Initializes a binding with the specified variable and value
        /// </summary>
        /// <param name="variable">The bound variable</param>
        /// <param name="value">The value to which the specified variable is bound</param>
        public VariableBinding(Variable variable, object value)
        {
            Contract.Requires(variable != null);

            // TODO: Ensure that the value is assignable to the variable type

            Variable = variable;
            Value = value;
        }
Пример #5
0
        /// <summary>
        /// Gets the value of the specified variable
        /// </summary>
        /// <param name="variable">The variable for which to get the value</param>
        /// <returns>The value of the specified variable</returns>
        /// <exception cref="UnboundVariableException">Thrown if the specified variable is not bound</exception>
        public object GetVariableValue(Variable variable)
        {
            Contract.Requires(variable != null);

            var binding = TryGetBinding(variable);

            if(binding == null)
            {
                throw new UnboundVariableException(variable, Resources.VariableNotBound.FormatInvariant(variable));
            }

            return binding.Value;
        }
Пример #6
0
        public static VariableExpression Expression(Variable variable)
        {
            Contract.Requires(variable != null);

            return new VariableExpression(variable);
        }
Пример #7
0
        protected override void Given()
        {
            _variable = new Variable("Grasp", "Test", typeof(int));

            _value = 1;
        }
Пример #8
0
        private VariableBinding TryGetBinding(Variable variable)
        {
            VariableBinding binding;

            _bindingsByVariable.TryGetValue(variable, out binding);

            return binding;
        }
Пример #9
0
        /// <summary>
        /// Sets the value of the specified variable
        /// </summary>
        /// <param name="variable">The variable for which to set the specified value</param>
        /// <param name="value">The new value of the specified variable</param>
        public void SetVariableValue(Variable variable, object value)
        {
            Contract.Requires(variable != null);

            var binding = TryGetBinding(variable);

            if(binding != null)
            {
                binding.Value = value;
            }
            else
            {
                binding = new VariableBinding(variable, value);

                _bindingsByVariable[variable] = binding;
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes an exception with the specified variable
        /// </summary>
        /// <param name="variable">The unbound variable</param>
        public UnboundVariableException(Variable variable)
        {
            Contract.Requires(variable != null);

            Variable = variable;
        }
Пример #11
0
 protected override void Given()
 {
     _outputVariable = new Variable("Grasp", "Test", typeof(int));
     _expression = Expression.Constant(0);
 }
Пример #12
0
        object IRuntimeSnapshot.GetValue(Variable variable)
        {
            Contract.Requires(variable != null);

            return null;
        }
Пример #13
0
        public static readonly ExpressionType ExpressionType = (ExpressionType) 1000; // Create a space separate from base expression trees

        #endregion Fields

        #region Constructors

        internal VariableExpression(Variable variable)
        {
            Variable = variable;
        }