My function get QueryString from some Web page as a string.
I need to parce it, to check, what strategy i must use.
Now my code looks ugly (i think so):
public QueryStringParser(string QueryString)
{
if (string.IsNullOrEmpty(QueryString))
{
this._mode = Mode.First;
}
else if (QueryString.Contains(_FristFieldName) && !QueryString.Contains(_SecondFieldName))
{
this._mode = Mode.Second;
}
else if (!QueryString.Contains(_FristFieldName) && QueryString.Contains(_SecondFieldName))
{
this._mode = Mode.Third;
}
else
{
throw new ArgumentException("QueryString has wrong format");
}
}
There must’n’t be both FieldNames in one QueryString.
How to change this code to be mo readable.
You could put the determination of the Mode into a separate method and return the Mode value; that way you can eliminate the if-else statements
[EDIT] Removed the double checking on the existance of field names and use variables instead.