首先,我使用www.codeeffects.com框架來創建一個業務規則評估器,但在我的情況下,我需要類型爲100%動態。給定的規則集不包含任何類型爲System.Object的規則,mscorlib,
我在我的概念驗證方法中有以下代碼。
public ActionResult Save(RuleModel ruleEditor)
{
DummyEntitiesGen gen = new DummyEntitiesGen();
Type t = gen.CreateType();
List<dynamic> lista= gen.CreateTypeList();
// At this point the rule model doesn't know which type to use as its source object
// We need to "bind" the source type to the rule model
ruleEditor.BindSource(t);
// Add the rule model to the ViewBag object
ViewBag.Rule = ruleEditor;
// Make sure that the Rule Area is not empty and the current rule is valid
if (ruleEditor.IsEmpty() || !ruleEditor.IsValid(StorageService.LoadRuleXml))
{
ViewBag.Message = "The rule is empty or invalid";
return View("Index");
}
try
{
// Save the rule
StorageService.SaveRule(
ruleEditor.Id,
ruleEditor.GetRuleXml(),
ruleEditor.IsLoadedRuleOfEvalType == null ?
true : (bool)ruleEditor.IsLoadedRuleOfEvalType);
// Get all rules for Tool Bar and context menus and save it in the bag
this.LoadMenuRules();
DynamicEvaluator evaluator = new DynamicEvaluator(ruleEditor.GetRuleXml());
//bool success = evaluator.Evaluate(lista, ruleEditor.Id);
IEnumerable<dynamic> result = lista.Filter<dynamic>(ruleEditor.GetRuleXml());
//var result = lista.AsQueryable<t>().Filter(ruleEditor.GetRuleXml());
ViewBag.Message = "The rule was saved successfully";
}
catch (Exception ex)
{
ViewBag.Message = ex.Message;
}
return View("Index");
}
對象列表很好,並返回一個創建的動態類型列表,我可以在調試時看到它。
但是這應該是高效過濾器是給我這個異常的行:
給定的規則集不包含具有System.Object類型的任何規則,mscorlib中