I am trying to work a dynamic way to define conditional rules that need to apply to data in a report. What I want is to allow the end user specify the conditions in a configuration, which is then compiled and executed when the report is run.
Now if done in code, I would have something like the code below.
public int showTopEntries{get; set;}
. . . .
showTopEntries = showTopEntries >= totalEntries ? totalEntries : showTopEntries;
However since I would prefer to have the user provide this rule in a text file, where it is read and translated, in code. How can I parse a string of the form(below) into the statement above please?
PropertyToSet= "showTopEntries" Condition ="showTopEntries >= totalEntries" ifTrue="totalEntries" ifFalse="showTopEntries"
Ultimately, I would like to have users defined rules in the form
<IfCondition>
<WhenTrue><\WhenTrue>
<WhenFalse>
<IfCondition>
<WhenTrue>
<IfCondition>
. . . . .
<\IfCondition>
<\WhenTrue>
<\IfCondition>
<\WhenFalse>
<\IfCondition>
Basically, if I have an object
public class PersonDetail { public String Name{get; set;} public String Description{get; set;} public String Age{get; set;} public Boolean Alive{get; set;} public MaritalStatus MaritalStatus {get; set;} public Address Address{get; set;} }
And I needed to apply a conditional replace of, say a substring, the name, using the following expression
public static class DetailExtender
{
public static void EvaluateConditionalFieldRule(this PersonDetail Detail, String PropertyToEvaluate, String ConditionalExpression, List<String> parameters, String IfTrue, String ifFalse)
{
var property = Detail.GetType().GetProperties().Where(x=>x.Name == PropertyToEvaluate);
if (property == null)
throw new InvalidDataException("Please specify a valid Detail property name for the evaluation.");
//put together the condition like so
if (Detail.AsQueryable().Where(ConditionalExpression, parameters).Count() > 0)
{
// property.Value = IfTrue;
}
else
{
property.Value = ifFalse;
}
}
}
Thanks in advance for your suggestions.