Send As SMS

Monday, July 04, 2005

ReadOnly SortedList [Coding]

Overview

It's common task to hold information in some kind of array or collection and provide user's of your component with read only access. For example we have ArrayList.ReadOnly(ArrayList list) for System.Collection.ArrayList. It creates read only array wrapper for you data. However, we do not have same feature for sorted list, which is also very good for storing internal data.

Implementation

SortedList have virtual property bool ReadOnly which always return false by default. When we override it, we will have possibility to control this feature.
In current implementation I've implemented 2 methods - LockReadOnly and UnlockReadOnly, which change state of ReadOnly property. To ensure that only correct code able to change list, Lock return a random key which is required to unlock a list.

Sources here [4k], written on C#.

Applies to all dotnet languages: C#, VB.NET, C++.NET, J#

0 Comments:

Post a Comment

<< Home