DataAccessAdapter.FetchProjection method signature

Posts   
 
    
Marcus avatar
Marcus
User
Posts: 747
Joined: 23-Apr-2004
# Posted on: 22-Jul-2006 20:36:04   

Frans,

I've gone through the DataAccessAdapter.FetchProjection method (which is fantastic BTW!) and I see that the List<IDataValueProjector> is only ever read... This is GOOD as I wish build some static fields to contain all my projectors as there is no point in buidling them over and over again.

However I never fully trust this kind of thing (things can change in the future) and ALWAYS create ReadOnly lists in order to ensure that we have thread safety.

When I build my ValueProjector list I want to save it as a ReadOnly list like:


internal sealed class ItemSummaryReader : ItemSummaryReaderBase
{
    private static readonly IList<IDataValueProjector> _itemSummaryValueProjectorList;

    static ItemSummaryReader()
    {
        _itemSummaryValueProjectorList = CreateItemSummaryValueProjectors().AsReadOnly();
    }

    private static IList<IDataValueProjector> CreateItemSummaryValueProjectors()
    {
        IList<IDataValueProjector> valueProjectors = new List<IDataValueProjector>();
        valueProjectors.Add(new DataValueProjector(ItemSummaryFieldIndex.ItemID.ToString(), 0, typeof (long)));
        valueProjectors.Add(new DataValueProjector(ItemSummaryFieldIndex.FileUID.ToString(), 1, typeof (Guid)));
        valueProjectors.Add(new DataValueProjector(ItemSummaryFieldIndex.FileSystemID.ToString(), 2, typeof (short)));
        ...
    }
}

But this would require the FetchProjection API to support IList<> rather than List<>. Do you think this is something you might consider?

public void FetchProjection( IList<IDataValueProjector> valueProjectors, IGeneralDataProjector projector, IDataReader reader )

Marcus

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 22-Jul-2006 21:08:20   

Good suggestion. I'll see if it still leads to compilable code. It shouldn't make a difference for calling code so I can change this signature without probs.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 26-Jul-2006 13:53:03   

I can't change this, as the list is passed to the IGeneralDataProjector implementing object when a projection result has to be added. That interface uses List<.. >, not IList<..>. Changing the interface will break custom projector code.

Frans Bouma | Lead developer LLBLGen Pro