RulesEngine
RulesEngine copied to clipboard
Utils.GetTypedObject fails to type lists of objects with nullable values
The Utils.GetTypedObject
used by the RuleParameter
seems to fail to properly type my ExpandoObject when I pass it in.
Consider the following models:
public class UserModel {
public string Name { get; set }
public string Id { get; set; }
}
public class RoleModel {
public string Role { get; set }
public string Id { get; set; }
}
public class WorkflowModel {
public IEnumerable<UserModel> ResponsibleUsers { get; set; }
public IEnumerable<RoleModel> ResponsibleRoles { get; set; }
}
public class MyModel {
public ICollection<WorkflowModel> Workflows { get; set; }
}
The workflows
collection in MyModel
contains several workflows, each of which can either have a list of ResponsibleUsers or ResponsibleRoles.
If the first workflow only has ResponsibleUsers then the remaining workflows cannot have ResponsibleRoles because Utils.GetTypedObject only looks at the first item in a collection for types.
{
"workflows": [
{
"responsibleUsers": [
{ "name": "John", "id": "j-12" }
],
"responsibleRoles": null
},
{
"responsibleUsers": null,
"responsibleRoles": [
{ "role": "Admin", "id": "adm" }
]
}
]
}
The above JSON when put through a RuleParameter and then accessed again would look similar to the below:
{
"workflows": [
{
"responsibleUsers": [
{ "name": "John", "id": "j-12" }
],
"responsibleRoles": null
},
{
"responsibleUsers": null,
"responsibleRoles": [
{ }
]
}
]
}
This is because as explained above, the first workflow does not have any responsible roles, there is no type specified for other workflows from now on.
@n-rowe may i know why are you using ExpandoObject
and not directly a typed object?
The value is gathered from json so we don't have a solid type for it
Newtonsoft should infer the type from json data