c# - Generify classes that reference themselves -


Is there any way to generate these two classes?

  class tag 1 {public tag 1 guardian {Get; Set;}} class tag 2 {public tag 2 guardian {get; Set}}}  

So I will:

  class tag 1: tag {} class tag 2: tag {}  

does not seem to be, but it is possible that I missed some global.

Thanks to John, I ended up with the following solution:

  class tag 1: tag & lt; T & gt; {Parent T Parent {get; Set;} Public T addNew () {New T (back)} {Mother = (T) it;} // This works}}  

OK, a little messier than before, and the subclass needs to do a bit more work, but ...

  Public abstract class SelfRef & lt; T & gt; Where T: Sulfurf & lt; T & gt; {Private Readonly Funk & lt; T & gt; ChildFactory; Public T Parents {Received; Set; } Protected SelfRef (Func & lt; T & gt; childFactory) {this.childFactory = childFactory; } Public T AddNew () {Return Baby Factory (); }} Public Sealed Class Ref1: SelfRef & lt; Ref1 & gt; {Public Ref1 (): Base ((=) => New Reference 1 {Mother = This}} {}}  

I think that meets the requirements Note that you < Under code> SelfRef , you will have difficulty applying a hierarchy more than one level, but you do so, so do not worry :)

You can potentially make the child The new parents take the factory In fact, the relationship you really want - it can not be expressed in T = (the same type derived from selfRef & lt; T & gt;) - The reason why NET can not be expressed in the generic, the reason That is, you have a slight dirt. / P>


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -