c# - Typing variables holding instances of constrained generic classes -


I'm just starting to grab with generic and now (AB) using a very intricate section of my code Again (I'm using C # for only a short time, but I am quite experienced in other languages).

I have a heritage structure where my classes extend a base class. I have most of the functionality in the base class but I want to connect these children's classes with the examples of their siblings.

Here is a simplification of some relevant code:

  class ParentClass & lt; T & gt; Where T: ParentClass & lt; T & gt;, New () {Create Public Static T ({{New T (Return); } Private Object joinItem; Join Public Zero & lt; TJoinee & gt; (TJoinee items) where TJoinee: ParentClass & lt; Tōoinee & gt;, new () {joinItem = item; }} Category ChildOne: ParentClass & lt; ChildOne & gt; {} Class ChildTwo: ParentClass & lt; ChildTwo & gt; {}  

In place of this code, I can do something like this:

  var a = ChildOne.Create (); A.Join (New ChildTwo ());  

The problem is that I need to type in the form of the joinItem object when I actually call it ParentClass & lt; Something & gt; Can it write more specific types in joinItem ? Or am I very humiliating the language and should take a completely different approach?

Do you have ParentClass & lt; T & gt; Interface from > which is not dependent on T ? In this way the joining item can be typed in the interface.

It seems that you can do that why you are trying to do this ( ParentClass & lt

if that ParentClass & lt; T & Gt; If there is nothing in the interface, then

is not dependent on T , then T


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -