0

Given the simplified model below I want to write a rule that says MyCollection contains MyField, but all I get is the list of Data Source items to select as if the ValueInputType for collections only works for User. What should I change in the model to achieve that?

public class MyModel
{
    [Field(Settable = false, DataSourceName = "MyDataSource")]
    public int MyField { get; set; }

    [Field(Settable = false, ValueInputType = ValueInputType.All, DataSourceName = "MyDataSource"))]
    public List<int> MyCollection { get; set; }
}
Wagner DosAnjos
  • 6,304
  • 1
  • 15
  • 29

1 Answers1

0

Per the documentation here, numeric value-typed collections can only use ValueInputType.User (look for one of the "IMPORTANT!" headers in the middle of the article). Therefore, you can't use value of the MyField field in your rule conditions. You need to create an in-rule method to achieve that:

public bool Contains(List<int> collection, [Parameter(DataSourceName = "MyDataSource")] int i)
{
    return collection.Contains(i);
}

Having such an in-rule method, your rule could look like this:

Check if Contains(MyCollection, OneOfTheMembersOfMyDataSource) is True
Alex
  • 566
  • 1
  • 6
  • 14
  • Thanks. But this feature would be a nice enhancement given that both the collection and the field have the same Data Source. – Wagner DosAnjos Jun 03 '20 at 01:48
  • It's not about the data source. There are some issues with the reflection of numeric collections in terms of their use as params or values. Namely, in certain cases, it's impossible to compare the underlying types. Therefore, to guarantee the result only the InputType.User is allowed for the numeric value-typed collections. – Alex Jun 03 '20 at 20:59