You are here: Basics Operations & Concepts > Activation > Transparent Activation > Enhance Collections

Enhance Collections

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.

Can Be Enhanced: When Using Interfaces In Declaration

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);
    }
}
EnhancementLimitations.cs: Can be enhanced by the db4o-tools
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
EnhancementLimitations.vb: Can be enhanced by the db4o-tools

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);
    }
}
EnhancementLimitations.cs: Is enhanced to
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
EnhancementLimitations.vb: Is enhanced to

Cannot Be Enhanced: When Using Concrete Class In Declaration

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);
    }
}
EnhancementLimitations.cs: Cannot be enhanced by the db4o-tools
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
EnhancementLimitations.vb: Cannot be enhanced by the db4o-tools

Casts are dangerous

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.