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 ( if that is not dependent on ParentClass & lt
ParentClass & lt; T & Gt;
If there is nothing in the interface, then T
, then T
Comments
Post a Comment