Use case, a system where I want to provide predefined filters for search results. The filter is more or less stored as an expression tree and can be constructed using a rule editor.
I want to provide the user with an editor, select a property, select the operator and allow the user to provide or select a value to compare with.
[dropdown with properties = PriorityId] [dropdown with operators = Equals] [dropdown with values = IList()]
The challenge is that the user needs to get a list of values to select from and I am figuring out how to
I have thought about the following approach, and I would like to get your input on this.
- Decorate the property with an attribute
- The attribute maps a class responsible for returning possible values
- The mapping class implements an interface
When selecting the property from the rule editor I can invoke the mapping class via reflection to return the values.
namespace Tickets.Data.Model
{
public class Ticket : BaseModel
{
[RuleEditorCollectionMapping(typeof(GetPriorities))]
public string PriorityId { get; set; }
}
}
public class RuleEditorCollectionMappingAttribute : Attribute
{
private Type classType;
public RuleEditorCollectionMappingAttribute(Type classType)
{
this.classType = classType;
}
}
public interface IRuleEditorCollectionMapping{}
public class GetPriorities : IRuleEditorCollectionMapping
{
public static IList<TicketPriority> GetValues()
{
// query logic to build a list with values to be used in the rules editor when selecting PriorityId
return new List<TicketPriority>();
}
}
Aucun commentaire:
Enregistrer un commentaire