Returning readonly version of object
Hello,
Need urgent help. Hope for good solution.
I have two classes inherited from System.Collections.CollectionBase.
Code:
public class1: System.Collections.CollectionBase
{ //.. }
public class2: System.Collections.CollectionBase
{
private class1 obj = new class1();
public class1 MyReadOnlySubClass
{
get { return class1; }
}
//..
}
So I return class1 as property in class2. How to hide returned class'es methods such Add, Clear, Insert, RemoveAt? I only need ability to enumerate this class with foreach and get all child objects.
Regards in advance,
Andrius
Re: Returning readonly version of object
Also I think there may be same problem with class1's inner object collections.
If I could return readonly version of class1 in class2, then calling to inner object of this returned class, they would be read-write, not read-only.