Esempio n. 1
0
        public static string GetSymbol(this OverloadableCodeOperator source)
        {
            var res = source switch
            {
                OverloadableCodeOperator.Increment => "++",
                OverloadableCodeOperator.Decrement => "--",
                OverloadableCodeOperator.Plus => "+",
                OverloadableCodeOperator.Minus => "-",
                OverloadableCodeOperator.LogicalNegation => "!",
                OverloadableCodeOperator.BitwiseComplement => "~",
                OverloadableCodeOperator.TrueOperator => "true",
                OverloadableCodeOperator.FalseOperator => "false",
                OverloadableCodeOperator.Mul => "*",
                OverloadableCodeOperator.Div => "/",
                OverloadableCodeOperator.Mod => "%",
                OverloadableCodeOperator.Sum => "+",
                OverloadableCodeOperator.Sub => "-",
                OverloadableCodeOperator.LeftShift => "<<",
                OverloadableCodeOperator.RightShift => ">>",
                OverloadableCodeOperator.LessThan => "<",
                OverloadableCodeOperator.LessThanOrEqual => "<=",
                OverloadableCodeOperator.GreaterThan => ">",
                OverloadableCodeOperator.GreaterThanOrEqual => ">=",
                OverloadableCodeOperator.Equal => "==",
                OverloadableCodeOperator.Unequal => "!=",
                OverloadableCodeOperator.And => "&",
                OverloadableCodeOperator.XOr => "^",
                OverloadableCodeOperator.Or => "|",
                _ => throw new ArgumentOutOfRangeException(nameof(source), source, null),
            };

            return(res);
        }
Esempio n. 2
0
        public static int GetNumberOfArguments(this OverloadableCodeOperator source)
        {
            if (source == OverloadableCodeOperator.TrueOperator || source == OverloadableCodeOperator.FalseOperator)
            {
                return(0);
            }

            if (source.IsOneOf(Unary))
            {
                return(1);
            }

            if (source.IsOneOf(Binary))
            {
                return(2);
            }

            throw new ArgumentOutOfRangeException(nameof(source), source, null);
        }
Esempio n. 3
0
        public static string ToCodeRepresentation(this OverloadableCodeOperator source, object leftOrSingle = null, object right = null, string spaceBetweenBinOperatorAndArgument = null)
        {
            var symbol    = source.GetSymbol();
            var argsCount = source.GetNumberOfArguments();

            if (argsCount == 0)
            {
                return(symbol);
            }

            if (argsCount == 1)
            {
                var isPost = (source == OverloadableCodeOperator.Increment ||
                              source == OverloadableCodeOperator.Decrement);
                return(isPost ? $"{leftOrSingle}{symbol}" : $"{symbol}{leftOrSingle}");
            }

            return
                ($"{leftOrSingle}{spaceBetweenBinOperatorAndArgument}{source.GetSymbol()}{spaceBetweenBinOperatorAndArgument}{right}");
        }
Esempio n. 4
0
 public static bool IsUnary(this OverloadableCodeOperator source)
 {
     return(Unary.Contains(source));
 }
Esempio n. 5
0
 public static OverloadableCodeOperators Add(this OverloadableCodeOperator source, params OverloadableCodeOperator[] values)
 {
     return(ToFlags(values).Add(source));
 }
Esempio n. 6
0
 public static OverloadableCodeOperators Remove(this OverloadableCodeOperators source, OverloadableCodeOperator value)
 {
     return(source & (OverloadableCodeOperators) ~value);
 }
Esempio n. 7
0
 public static OverloadableCodeOperators Add(this OverloadableCodeOperators source, OverloadableCodeOperator value)
 {
     return(source | (OverloadableCodeOperators)value);
 }
Esempio n. 8
0
 public static bool Contains(this OverloadableCodeOperators source, OverloadableCodeOperator value)
 {
     return(((int)source & (int)value) != 0);
 }
Esempio n. 9
0
 public static OverloadableCodeUnarySymmetricOperator ToUnarySymmetricOperator(this OverloadableCodeOperator source)
 {
     return(source.IsOneOf(Unary | Symmetric)
                         ? (OverloadableCodeUnarySymmetricOperator)source
                         : throw new ArgumentException($"The {source} is not unary symmetric operator.", nameof(source)));
 }
Esempio n. 10
0
 public static bool IsNotAnyOf(this OverloadableCodeOperator source, OverloadableCodeOperators flags)
 {
     return(((int)source & (int)flags) == 0);
 }