1

我按照这里的演示项目https://codeeffects.com/Doc/Business-Rule-Flex-Source了解 Flex 属性如何工作的示例。我的规则评估正确,但编辑器不显示字段。

我查看了 FlexPropertyInfo 对象的所有属性,并确认它们的设置符合我的预期。为了解决这个问题,我还应该尝试什么?

4

1 回答 1

1
  1. 确保您的 Flex 类型继承自 Type 并实现最低要求的属性和方法,尤其是 GetProperties,例如:

     public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
     {
         List<FlexPropertyInfo> properties = new List<FlexPropertyInfo>();
         properties.Add(new FlexPropertyInfo("Id", typeof(int), typeName));
         properties.Add(new FlexPropertyInfo("Name", typeof(string), typeName));
    
         return properties.ToArray();
     }
    
  2. 确保传递 Flex 类型的新实例,而不是类型本身。

     RuleEditor editor = new RuleEditor("divRuleEditor")
     {
         Mode = Common.RuleType.Execution,
         SourceType = new MyFlexType() //and not typeof(MyFlexType)
     }
    

编辑器本身对 Flex 一无所知。就它而言,它是另一种类型,它使用反射来拉取所有成员的列表。这就是为什么传递您的类型的实例很重要的原因。否则,您将获得对 Type 类的反思。属性和其他 Flex 对象也是如此。

于 2021-11-02T04:54:01.063 回答