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); }
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); }
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}"); }
public static bool IsUnary(this OverloadableCodeOperator source) { return(Unary.Contains(source)); }
public static OverloadableCodeOperators Add(this OverloadableCodeOperator source, params OverloadableCodeOperator[] values) { return(ToFlags(values).Add(source)); }
public static OverloadableCodeOperators Remove(this OverloadableCodeOperators source, OverloadableCodeOperator value) { return(source & (OverloadableCodeOperators) ~value); }
public static OverloadableCodeOperators Add(this OverloadableCodeOperators source, OverloadableCodeOperator value) { return(source | (OverloadableCodeOperators)value); }
public static bool Contains(this OverloadableCodeOperators source, OverloadableCodeOperator value) { return(((int)source & (int)value) != 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))); }
public static bool IsNotAnyOf(this OverloadableCodeOperator source, OverloadableCodeOperators flags) { return(((int)source & (int)flags) == 0); }