microsoft / RulesEngine

A Json based Rules Engine with extensive Dynamic expression support
https://microsoft.github.io/RulesEngine/
MIT License
3.6k stars 543 forks source link

Public Factory Method for Rule Parameter From Type #529

Closed cmeyertons closed 1 month ago

cmeyertons commented 1 year ago

If the RuleParameter's type is only known via a Type at runtime, it becomes non-trivial to create a pseudo-object of that Type in order to create a RuleParameter. For instance, Activator.CreateInstance throws when attempting to create a string

It would be ideal if the RuleParameter could be created directly from the Name and Type pair as the internal implementation does.

In this PR, I elected to create a static factory method over publicizing the constructor to avoid overload confusion of Name, Value and Name, Type - theoretically a consumer could be passing in a Type into the object constructor, and publicizing the constructor could potentially be a breaking change.