I have a csv file in the below format :
This Rule sheet is loaded in a List<DoctypeRule>
object, I am using this list to fetch the DocType values based on the RuleCode and RuleValue. The DoctypeRule class looks like this
public class DoctypeRule
{
public string doctype {get; set; }
public string ruleCode {get; set; }
public string ruleValue {get; set; }
}
Now, to fetch a rule i use a LINQ and pass a parameter.
DoctypeRule rule = new DoctypeRule();
rule = lsdoctypeRules.Find(r => r.docType == myparameter);
Also i want to fetch the doctype with similar rules and store in a list. Since some of the RuleValue will have comma separated values, i am not able to fetch the doctypes with similar rules Example :
string ruleCode = rule.ruleCode;;
string ruleValue = rule.ruleValue;
List<string> lsruleValues = ruleValue.Split(',').ToList();
Now to collect doctypes with similar rule i used
var siblingDoctypes = lsdoctypeRules
.Where(r => r.ruleValue == ruleValue && r.ruleCode == ruleCode)
.Select(x => x.docType);
This is good to fetch doctypes when RuleValue is having only one value. But when comma separated values are there i tried something like this
var siblingDoctypes = lsdoctypeRules
.Where(r => r.ruleValue.Split(',').ToList().Any(lsruleValues.Any().ToString()) && r.ruleCode == ruleCode)
.Select(x => x.docType);
What is expected is if lsruleValues
has 4 items
Title Policy Schedule A,Title Policy Schedule B-Part I,Title Policy Schedule B-Part II,Title Policy
Then sibling Doctypes should be a list of
Title Endorsement, Title Policy Schedule A,Title Policy Schedule B-Part I,Title Policy Schedule B-Part II.