static SyntaxKind ToSyntaxKind(this AssignmentKind kind)
        {
            switch (kind)
            {
            case AssignmentKind.Set: return(SyntaxKind.SimpleAssignmentExpression);

            case AssignmentKind.Add: return(SyntaxKind.AddAssignmentExpression);

            case AssignmentKind.Subtract: return(SyntaxKind.SubtractAssignmentExpression);

            case AssignmentKind.Multiply: return(SyntaxKind.MultiplyAssignmentExpression);

            case AssignmentKind.Divide: return(SyntaxKind.DivideAssignmentExpression);

            case AssignmentKind.Modulo: return(SyntaxKind.ModuloAssignmentExpression);

            case AssignmentKind.And: return(SyntaxKind.ModuloAssignmentExpression);

            case AssignmentKind.ExclusiveOr: return(SyntaxKind.ExclusiveOrAssignmentExpression);

            case AssignmentKind.Or: return(SyntaxKind.OrAssignmentExpression);

            case AssignmentKind.LeftShift: return(SyntaxKind.LeftShiftAssignmentExpression);

            case AssignmentKind.RightShift: return(SyntaxKind.RightShiftAssignmentExpression);

            default:
                throw new ArgumentOutOfRangeException(nameof(kind), kind, null);
            }
        }
        public static string AssignmentType(AssignmentKind kind)
        {
            switch (kind)
            {
            case AssignmentKind.AddEquals:
                return("+=");

            case AssignmentKind.BitwiseAndEquals:
                return("&=");

            case AssignmentKind.BitwiseOrEquals:
                return("|=");

            case AssignmentKind.BitwiseXorEquals:
                return("^=");

            case AssignmentKind.DivideEquals:
                return("/=");

            case AssignmentKind.Equals:
                return("=");

            case AssignmentKind.ModEquals:
                return("%=");

            case AssignmentKind.MultiplyEquals:
                return("*=");

            case AssignmentKind.SubtractEquals:
                return("-=");

            default:
                throw new GraphViewException("Invalid assignment kind.");
            }
        }
Exemplo n.º 3
0
 public static string AssignmentType(AssignmentKind kind)
 {
     switch (kind)
     {
         case AssignmentKind.AddEquals:
             return "+=";
         case AssignmentKind.BitwiseAndEquals:
             return "&=";
         case AssignmentKind.BitwiseOrEquals:
             return "|=";
         case AssignmentKind.BitwiseXorEquals:
             return "^=";
         case AssignmentKind.DivideEquals:
             return "/=";
         case AssignmentKind.Equals:
             return "=";
         case AssignmentKind.ModEquals:
             return "%=";
         case AssignmentKind.MultiplyEquals:
             return "*=";
         case AssignmentKind.SubtractEquals:
             return "-=";
         default:
             throw new GraphViewException("Invalid assignment kind.");
     }
 }
        public static AssignmentSetClause AssignmentSetClause(AssignmentKind kind, ColumnReferenceExpression column, ScalarExpression newValue)
        {
            var fragment = new AssignmentSetClause();

            fragment.AssignmentKind = kind;
            fragment.Column         = column;
            fragment.NewValue       = newValue;
            return(fragment);
        }
        public static SyntaxNode SetProperty(RoslynTranslator translator, AssignmentKind kind,
                                             IPortModel instancePortModel, IPortModel valuePortModel, params string[] members)
        {
            ExpressionSyntax instance = instancePortModel.Connected
                ? translator.BuildPort(instancePortModel).FirstOrDefault() as ExpressionSyntax
                : SyntaxFactory.ThisExpression();
            ExpressionSyntax value = translator.BuildPort(valuePortModel).FirstOrDefault() as ExpressionSyntax;

            return(SetProperty(kind, instance, value, members));
        }
        public static SyntaxNode SetProperty(AssignmentKind kind, ExpressionSyntax instance, ExpressionSyntax value,
                                             params string[] members)
        {
            instance = members.Aggregate(instance, (current, t) =>
                                         SyntaxFactory.MemberAccessExpression(
                                             SyntaxKind.SimpleMemberAccessExpression,
                                             current,
                                             SyntaxFactory.IdentifierName(t)));

            return(SyntaxFactory.ExpressionStatement(
                       SyntaxFactory.AssignmentExpression(
                           kind.ToSyntaxKind(),
                           instance,
                           value))
                   .NormalizeWhitespace());
        }
Exemplo n.º 7
0
        public static object Evaluate(AssignmentKind kind, object current, object value)
        {
            // TODO: use switch expression, expression bodied member
            switch (kind)
            {
            case AssignmentKind.Equals:
                return(value);

            case AssignmentKind.AddEquals:
                // TODO: handle numeric conversions properly
                // TODO: and how do nulls work?
                if (current == null || value == null)
                {
                    return(current ?? value);
                }
                if (current is int i && value is int j)
                {
                    return(i + j);
                }
                return((decimal)current + (decimal)value);

            case AssignmentKind.SubtractEquals:
                return((decimal)current - (decimal)value);

            case AssignmentKind.MultiplyEquals:
                return((decimal)current * (decimal)value);

            case AssignmentKind.DivideEquals:
                return((decimal)current / (decimal)value);

            case AssignmentKind.ModEquals:
                return((decimal)current % (decimal)value);

            case AssignmentKind.BitwiseAndEquals:
                return((int)current & (int)value);

            case AssignmentKind.BitwiseOrEquals:
                return((int)current | (int)value);

            case AssignmentKind.BitwiseXorEquals:
                return((int)current ^ (int)value);

            default:
                throw FeatureNotSupportedException.Value(kind);
            }
        }
Exemplo n.º 8
0
 public StatementAssign(AssignmentKind op, Token var, Expression value)
 {
     this.op    = op;
     this.var   = var;
     this.value = value;
 }