Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils.GetTypedObject fails to type lists of objects with nullable values #577

Open
n-rowe opened this issue Jan 22, 2024 · 2 comments
Open

Comments

@n-rowe
Copy link

n-rowe commented Jan 22, 2024

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.

@abbasc52
Copy link
Contributor

abbasc52 commented Jan 26, 2024

@n-rowe may i know why are you using ExpandoObject and not directly a typed object?

@n-rowe
Copy link
Author

n-rowe commented Jan 26, 2024

The value is gathered from json so we don't have a solid type for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants