patterncsharpMinor
How best to differentiate boolean values in a long list?
Viewed 0 times
differentiatebooleanlonghowvalueslistbest
Problem
I have a large C# Dictionary of string keys and boolean values. Background on the reason for it is this: my program builds up a bunch of the same objects from two different sources, and then compares all the properties to see if there are any disparates. But I want to ignore the differences where I know one source hasn't exposed that property for comparison, so I have this array that lists the properties that are actually 'gathered'.
Then when filtering the differences before user display, I ask
The problem with this is th
Then when filtering the differences before user display, I ask
if(!gathered[prop]) and remove it in that case. It would throw an exception if I hadn't defined a case for the property, and I don't want to ignore that as it may just mean I neglected to specify if it was or wasn't gathered.public Dictionary TPORGatheredData = new Dictionary()
{
// Represents fields that are actually retrieved from TP data
{ "Reference", true },
{ "Title", true },
{ "Status", true },
{ "Status.State", true },
{ "OriginatorName", true },
{ "InvestigatorName", true },
{ "ManagerName", true },
{ "ObservedOn", true },
{ "RaisedOn", true },
{ "ClosedOn", true },
{ "Project", true },
{ "VariantObservedOn", true },
{ "SoftwareVersionObserved", true },
{ "AreaObservedOn", true },
{ "StageObservedOn", true },
{ "VariantAppliedTo", true },
{ "AreaAppliedTo", true },
{ "FaultClassification", true },
{ "Type", true },
{ "SecurityClassification", true },
{ "CommercialClassification", true },
{ "SecurityGroup", true },
{ "SafetyRelated", true },
{ "Description", false },
{ "Recommendations", true },
{ "Recommendations.PointNumber", true },
{ "Recommendations.Id", true },
{ "Recommendations.Type", true },
{ "Recommendations.RecommendationText", true },
{ "ClosureText", true },
};The problem with this is th
Solution
Is this more like what you're after?
var TPORGatheredData = new[]
{
// Add all values in the logical order that you want them
"Reference",
"Title",
"Status",
"Status.State",
//...omitted for brevity
"Description",
"ClosureText"
}.ToDictionary(x=>x,x=>true);
// This is significant
TPORGatheredData["Description"] = false;Code Snippets
var TPORGatheredData = new[]
{
// Add all values in the logical order that you want them
"Reference",
"Title",
"Status",
"Status.State",
//...omitted for brevity
"Description",
"ClosureText"
}.ToDictionary(x=>x,x=>true);
// This is significant
TPORGatheredData["Description"] = false;Context
StackExchange Code Review Q#32188, answer score: 8
Revisions (0)
No revisions yet.