You can use the normal .NET-collections in your code and then replace the implementations with the enhancement-tools. See "TA Enhanced Example"
The enhancement tools will search for instantiations of collections and replace it with an appropriate transparent activation aware collection.
However this has some implications. The original collection-classes are all sealed and not designed for extension. This means that a complete different implementation is used and has consequences.
The best case is when collection-interface is used, like IList instead of the concrete class. For example a field-declaration like this:
public class CanBeEnhanced { private IList<string> _names = new List<string>(); public bool ContainsName(string item) { return _names.Contains(item); } public void AddName(string item) { _names.Add(item); } }
Public Class CanBeEnhanced Private _names As IList(Of String) = New List(Of String)() Public Function ContainsName(ByVal item As String) As Boolean Return _names.Contains(item) End Function Public Sub AddName(ByVal item As String) _names.Add(item) End Sub End Class
Are correctly translated by the enhancement tools to:
public class CanBeEnhanced { private IList<string> _names = new ActivatableList<string>(); public bool ContainsName(string item) { return _names.Contains(item); } public void AddName(string item) { _names.Add(item); } }
Public Class CanBeEnhanced Private _names As IList(Of String) = New ActivatableList(Of String)() Public Function ContainsName(ByVal item As String) As Boolean Return _names.Contains(item) End Function Public Sub AddName(ByVal item As String) _names.Add(item) End Sub End Class
When you use the concrete types in field declarations, the enhancer-tools will produce a warning and doesn't change the implementation. The example below cannot be enhanced, because it uses the concrete type.
public class CannotBeEnhanced { // cannot be enhanced, because it uses the concrete type private List<string> _names = new List<string>(); public bool ContainsName(string item) { return _names.Contains(item); } public void AddName(string item) { _names.Add(item); } }
Public Class CannotBeEnhanced ' cannot be enhanced, because it uses the concrete type Private _names As New List(Of String)() Public Function ContainsName(ByVal item As String) As Boolean Return _names.Contains(item) End Function Public Sub AddName(ByVal item As String) _names.Add(item) End Sub End Class
The enhancement tools replace the implementation of collections. When you code has an assumptions about the concrete types and tries to cast, it may fail. In general try to avoid casting to concrete types and use interfaces instead.