I have a list of rule names coming from .xml file. These rule names needs to be validated against rule names in database (Validator.cs)
. If valid, then Id
of these rule names are used to fetch user data from database (ExportService.cs
).
I am using a Dictionary
object to save name, Id pair from database -
Validator.cs
var rulesDictionary = new Dictionary<string, string>();
while (sqlDataReader.Read())
{
string ruleName = sqlDataReader["NAME"].ToString();
string ruleLink = sqlDataReader["LINK"].ToString();
rulesDictionary.Add(ruleName, ruleLink);
}
The values coming from XML file are validated against this dictionary as -
ExportService.cs
if (DepositRulesDictionary.ContainsKey(xmlRuleName1) == false)
{
//log error
}
If all the values are valid, then this dictionary is further used to pass 'ruleLink' values in ExportService.cs.
I used Dictionary object in this instance as it returns O(1) result for validating XML file values.
My XML file is not going to be very big, so efficiency is not a major concern right now.
My question is what is more recommended -
Dictionary<string, string>
object orList<T>
where T is having two properties of Name and Link.
For scalability and unit-testability?
ContainsKey
but useTryGetValue
. \$\endgroup\$ – BCdotWEB Mar 29 '20 at 19:13