public override FlowState Execute(ScopeRuntimeContext context)
        {
            switch (operatorType)
            {
            case Operator.AndEquals:
                if (!assignee.GetAs <bool>(context))
                {
                    //Short Circuiting
                    //No need to set anything
                    break;
                }
                assignee.SetAs(context, value.GetAs <bool>(context));
                break;

            case Operator.OrEquals:
                if (assignee.GetAs <bool>(context))
                {
                    //Short Circuiting
                    //No need to set anything
                    break;
                }
                assignee.SetAs(context, value.GetAs <bool>(context));
                break;

            default:
                throw new ArgumentException($"Unexpected Operator: {operatorType}");
            }

            return(FlowState.Nominal);
        }
Ejemplo n.º 2
0
        public static async Task <T?> GetProperty <T>(this IVisualElement element, string propertyName)
        {
            if (element is null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            IValue value = await element.GetProperty(propertyName);

            return(value.GetAs <T?>());
        }
Ejemplo n.º 3
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (assigneeType == typeof(int))
            {
                assignee.SetAs(context, assignee.GetAs <int>(context) + value.GetAs <int>(context));
            }
            else if (assigneeType == typeof(double))
            {
                assignee.SetAs(context, assignee.GetAs <double>(context) + value.GetAs <double>(context));
            }
            else if (assigneeType == typeof(string))
            {
                assignee.SetAs(context, assignee.GetAs <string>(context) + GetStringValue(value, context));
            }
            else
            {
                throw new ScriptRuntimeException(
                          $"Incompatible types for operator {Operator.PlusEquals}: {assignee} of type {assigneeType.Name} and {value} of type {value.GetValueType().Name}");
            }

            return(FlowState.Nominal);
        }
Ejemplo n.º 4
0
        public static async Task <T?> GetProperty <T>(this IVisualElement element, DependencyProperty dependencyProperty)
        {
            if (element is null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            if (dependencyProperty is null)
            {
                throw new ArgumentNullException(nameof(dependencyProperty));
            }

            IValue value = await element.GetProperty(dependencyProperty.Name, dependencyProperty.OwnerType.AssemblyQualifiedName);

            return(value.GetAs <T?>());
        }
        private void Modify(RuntimeContext context)
        {
            int diff = increment ? 1 : -1;

            if (valueType == typeof(int))
            {
                //Modify as Integer
                arg.SetAs(context, arg.GetAs <int>(context) + diff);
            }
            else
            {
                //Modify as Double
                arg.SetAs(context, arg.GetAs <double>(context) + diff);
            }
        }
Ejemplo n.º 6
0
        public override FlowState Execute(ScopeRuntimeContext context)
        {
            if (assigneeType == typeof(int))
            {
                switch (operatorType)
                {
                case Operator.PlusEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) + value.GetAs <int>(context));
                    break;

                case Operator.MinusEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) - value.GetAs <int>(context));
                    break;

                case Operator.TimesEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) * value.GetAs <int>(context));
                    break;

                case Operator.DivideEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) / value.GetAs <int>(context));
                    break;

                case Operator.PowerEquals:
                    assignee.SetAs(context, (int)Math.Pow(assignee.GetAs <int>(context), value.GetAs <int>(context)));
                    break;

                case Operator.ModuloEquals:
                    assignee.SetAs(context, assignee.GetAs <int>(context) % value.GetAs <int>(context));
                    break;

                default: throw new ArgumentException($"Unexpected Operator: {operatorType}");
                }
            }
            else if (assigneeType == typeof(double))
            {
                switch (operatorType)
                {
                case Operator.PlusEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) + value.GetAs <double>(context));
                    break;

                case Operator.MinusEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) - value.GetAs <double>(context));
                    break;

                case Operator.TimesEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) * value.GetAs <double>(context));
                    break;

                case Operator.DivideEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) / value.GetAs <double>(context));
                    break;

                case Operator.PowerEquals:
                    assignee.SetAs(context, Math.Pow(assignee.GetAs <double>(context), value.GetAs <double>(context)));
                    break;

                case Operator.ModuloEquals:
                    assignee.SetAs(context, assignee.GetAs <double>(context) % value.GetAs <double>(context));
                    break;

                default: throw new ArgumentException($"Unexpected Operator: {operatorType}");
                }
            }
            else
            {
                throw new ScriptRuntimeException(
                          $"Incompatible types for operator {operatorType}: {assignee} of type {assigneeType.Name} and {value} of type {value.GetValueType().Name}");
            }

            return(FlowState.Nominal);
        }