Binding to Collections

  • Updated

Historically, an object exposing collection properties required the .NET collection type to implement either IList or IList<T> in order to be used in a .NET Assembly Schema binding.

With the release of InRule v5.3.0, support for collection types in assembly schemas has been expanded. The following collection types are now supported (with corresponding feature sets):

 

Add Member

Remove Member

Clear

Sort

Get Member by Index

Set Member by Index

IList

Yes*

Yes

Yes

Yes

Yes

Yes

IList<T>

Yes

Yes

Yes

Yes

Yes

Yes

ICollection<T>

Yes

Yes**

Yes

No

Yes***

No

IEnumerable<T>

No

No

No

No

Yes***

No

Arrays

No

No

No

Yes

Yes

Yes

 

* Type of collection property may implement IList but cannot be declared as IList because InRule cannot infer the type of the collection member to instantiate.

** ICollection<T> collections can only remove items by object, not by index, therefore this only works if the member object at the index being removed does not exist in the same collection more than once; if it does, an Exception will be thrown because the collection would only remove the first instance of the object in the collection, which may not be the desired index.

*** ICollection<T> and IEnumerable<T> do not ensure deterministic ordering of items that they contain, however most implementations tend to enumerate the items in the same order each time. Addressing a specific index in these collections is emulated by advancing the enumerator the desired number of times to access the member by index.

Was this article helpful?

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.