Re: "Private" nested classes
From: Mikolas (Mikolas_at_discussions.microsoft.com)
Date: 07/29/04
- Next message: LEBRUN Thomas: "RE: How to detect network cable disconnection"
- Previous message: Jon Skeet [C# MVP]: "Re: "Private" nested classes"
- In reply to: Etienne Boucher: "Re: "Private" nested classes"
- Next in thread: Etienne Boucher: "Re: "Private" nested classes"
- Reply: Etienne Boucher: "Re: "Private" nested classes"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 29 Jul 2004 06:08:01 -0700
The perfect solution would probably be making the constructor of the internal class visible only to the outter class. I'm not aware of a technique that would enable that. Or in c++ there's the friend keyword, which hasn't been adopted into C#(as far as I now)
Wouldn't making the inner constructor private solved the problem though?
"Etienne Boucher" wrote:
> The goal is to still be able to access the members of the nested type from
> outside the outter class. From the definition
>
> public class Outter
> {
> private Inner i;
>
> public Outter()
> {
> new Inner(this);
> }
>
> public Inner InnerAccessor
> {
> get { return i; }
> }
>
> public class Inner
> {
> private Outter o;
> public int MemberInt;
>
> public Inner(Outter o)
> {
> if (null != o.i)
> throw new Exception();
> o.i = this;
> this.o = o;
> }
> }
> }
>
> The following code can still be exectuted.
>
> Outter o = new Outter();
> Console.WriteLine(o.InnerAccessor.MemberInt);
>
> Again, if anyone knows a better way to do this.
>
> Etienne Boucher
>
>
>
- Next message: LEBRUN Thomas: "RE: How to detect network cable disconnection"
- Previous message: Jon Skeet [C# MVP]: "Re: "Private" nested classes"
- In reply to: Etienne Boucher: "Re: "Private" nested classes"
- Next in thread: Etienne Boucher: "Re: "Private" nested classes"
- Reply: Etienne Boucher: "Re: "Private" nested classes"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|