Hi all,
I have the following simple class which I use to store a set of lab
objects:
/// <summary>
/// Represents a Collection of Labs
/// </summary>
public class CLabCollection
{
// stores a set of labs
public ArrayList labCollection = new ArrayList();
/// <summary>
/// Get/Set the collection of Labs
/// </summary>
public Lab[] LabCollection
{
get
{
Lab[] tempLabCollection = new
Lab[labCollection.Count];
labCollection.CopyTo(tempLabCollection);
return tempLabCollection;
}
set
{
if (value == null) return;
Lab[] tempCLabCollection = (Lab[])value;
labCollection.Clear();
foreach (Lab lab in tempCLabCollection)
labCollection.Add(lab);
}
}
/// <summary>
/// Returns the collection of labs as an ArrayList. Since
ArrayList is inherited from IList,
/// it can be bound to a control
/// </summary>
public ArrayList LabArrayList
{
get
{
return labCollection;
}
}
/// <summary>
/// Constructor
/// </summary>
public CLabCollection(){}
/// <summary>
/// Add a Lab to the Collection.
/// </summary>
/// <param name="lab"></param>
public void Add(Lab lab)
{
labCollection.Add(lab);
}
/// <summary>
/// Get the first Lab in the Collection. Exception thrown if
none exists
/// </summary>
public Lab FirstLab
{
get
{
if (labCollection.Count == 0)
throw new ApplicationException("Can't get first
Lab in Lab Collection since it is empty.");
return (Lab)labCollection[0];
}
}
}
It then become easy to serialise to objects of CLabCollection as
follows:
class CFramework
{
CLabCollection labCollection = new CLabCollection();
public ArrayList LabArrayList
{
get
{
return labCollection.LabArrayList;
}
}
public CFramework()
{
XmlSerializer xmlSerializer = new
XmlSerializer(typeof(CLabCollection));
using (StreamReader streamReader = new
StreamReader(xmlLabDirectoriesPath))
{
labCollection =
(CLabCollection)xmlSerializer.Deserialize(streamRe ader);
}
}
}
Then in my MainForm I can do something like this:
CurrencyManager currencyManagerLab =
(CurrencyManager)this.BindingContext[Environment.Framework.LabArrayList,
null];
In your opinion is this a good approach, and if not, why not? I'm
expossing the same array (CLabCollection:labCollection) via two
seperate accessors (LabCollection and LabArrayList), but this feels
correct to me since I'm using it the array for two different purposes.
Thanks,
Aine