c# - Non-constructed generics as properties (eg. List<T>) -


problem

There is something that came to me some time ago and in some way to work around it Was able to But now it came back after feeding on my curiosity - and I would love to give a definitive answer.

Actually, I have a general DGV basegrid view and lieutenant; T & gt; : Datagrid view where T: class . Types created based on basegrid view (such as invoicedgrid view: basegrid view & lt; invoice & gt; ), of later shared functionality provided by Used to display various business items using Basgrid view (such as virtual mode, buttons, etc.)

It is now necessary to create a user control that shared from BaseGridView to / em> functionality (eg. Filtering). So I was hoping to create a public property on user control which I would like to do in any BaseGridView designer / code: public basegrid view & lt; T & gt; MyGridView {Get; Set; } . The problem does not work :-) When compiled, I get the following message:

type or name space name 't' could not be found or an assembly reference?)

Solution?

I see that I can remove the shared functionality as an interface, Icon BaseGridView implementation, and then see the interface built in my uesr control.

But I'm curious if there are some Secret C # commands / syntax which will help me achieve - without actually polluting my solution with my interface, I really do not need to: - )

Edit : For reference, I tried this innocent solution: Bestsgrid view & lt; Object & gt; MyGridView {Get; Set; } , and ... it still does not answer: type 'invoice grid view' to 'bassgrid view & lieutenant; Object & gt; ' can not be converted from conversion.

Partial success (edit 2)

OK, because the sensation is only supported on the interface, I accepted and define one interface (only something shown in it) :

  Public Interface ibasegrid view & lt; Out t & gt; Where T: Class {bool ScrollTo (Predicate & lt; T & gt; Criterion); Bowl Scrollto (T-object); }  

Now I will add my sweet InvoiceGridView to a IBaseGridView & lt; Object & gt; - That's awesome And I'm a happy boy again :-) However, the second ScrollTo is having trouble with the compilation:

Invalid variance: Type parameter 'T' should be misleading on GeParts.Controls.IBaseGridView.ScrollTo (T) '. 'T' is a cult.

I now have to modify the signature on ScrollTo (object o) - which is not ideal but the work is completed. I was surprised that the compiler had complained about the second ScrollTo , still happy with the first one, it looks like someone example outside the example Not allowed to pass, but using this type of self (for example, predicate> ) is OK? It seems that ... ...

Since you wrote

< P> But I have some curious C # commands / syntax which will help me to achieve what I have to achieve

I would like to add that generated for C # 4.0 basis Makes it possible to type a place & lt; Outside t> You can do this for sympathy

Public Bassgrid view & lt; Object > MyGridView {get; Set; }

Then you get a known type, but you can return whatever you can see the basgrid view. Unfortunately, only one hold is that interactivity is allowed on the interface itself! :(


Comments