I am receiving and Expression (String) as follows:
String expression = "+name;-age;-city";
I parse this expression by splitting it using ";"
and interpreting the +/- signs and create a List<OrderRule>
. To wrap this I created the following:
public class OrderExpression {
public HashSet<OrderRule> Rules { get; set; }
public static Boolean TryParse(String expression, out OrderExpression orderExpression) {
// Parse expression into a List<OrderRule>
if (_parser.ExpressionIsValid(expression)) {
orderExpression = new OrderExpression { Rules = _parser.Parse(expression) }
return true;
else
return false;
}
}
So I would use it as follows:
String expression = "+name;-age;-city";
OrderExpression orderExpression;
OrderExpression.TryParse(expression, out orderExpression);
Does this make sense? I am not sure if this architecture and naming is the way to go.
I am being picky about this because I will use it as a standard for an API to convert an order expression into a List.