I am doing the following about 10 times with other strings, so the code is duplicated. How can I refactor this?
queryWhere
is a Dictionary<string,string>
that contains parameters that will be passed to a query.
string account = string.Empty;
if (queryWhere.ContainsKey("account")
&& queryWhere["account"] != null
&& !string.IsNullOrEmpty(queryWhere["account"].ToString()))
account = queryWhere["account"].ToString();
string customer = string.Empty;
if (queryWhere.ContainsKey("customer ")
&& queryWhere["customer "] != null
&& !string.IsNullOrEmpty(queryWhere["customer "].ToString()))
customer = queryWhere["customer "].ToString();
string balance = string.Empty;
if (queryWhere.ContainsKey("balance ")
&& queryWhere["balance "] != null
&& !string.IsNullOrEmpty(queryWhere["balance "].ToString()))
balance = queryWhere["balance"].ToString();
queryWhere
? \$\endgroup\$ – BCdotWEB Apr 17 '15 at 15:30