I have a private member of type List<T>
where the T
are rich domain objects. The domain in my application contains many methods that expect a T
.
I want to expose only a public property of type IList<IT>
where T : IT
. IT
has a small footprint which is implemented by a DTO.
Since I cannot cast a List<T>
to IList<IT>
I am resorting to using List<T>.ConvertAll
in the property declaration.
Is this there a better way to do this? Faster, more elegant?
Edit to provide additional detail
The T
are a base class, for which a number of derived classes exist, and each of these derived classes comes in many different flavors (configurations loaded in runtime). The user in the presentation layer can add/change/remove any instances of these derived classes of any configuration. The instances can also be linked directionally to each other by the user, but there are some complex rules that govern what links are allowed; some known at compile time, some known only at runtime (based on the configurations). Some instances may be double-linked, some cross-linked, some only single in either direction, some in only one direction, and some not at all.
For this purpose the T
contains a list of the valid targets for any such links. The presentation layer graphically highlights these valid targets and does not allow linking if the targets are not in the valid list. When any instance is newly created, changed or removed the ValidTargets list of each instance needs to be re-evaluated and may change.
There is a lot of other members and methods on the T
class that the factory and services classes expect to operate on. Some behave very similar to the example above. None of these should be exposed outside of the assembly.