Re: Feature request for C# Generic inheritence

Tech-Archive recommends: Speed Up your PC by fixing your registry



This is correct. I thought that for generic inheritance, the compiler will create an explicit type at compile time. Same way anonymous method works.

"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message news:#oRPonIAIHA.1168@xxxxxxxxxxxxxxxxxxxxxxx
The trouble is that .NET generics, unlike C++ templates, are completely compiled in generic form. However, all base classes must be known at compile time. Only C++ templates, which are made concrete before being compiled, can inherit from template parameters. However .NET classes can use the curiously recurring template pattern which has some overlapping applications.



"Ido Samuelson" <isamuelson@xxxxxxxxxx> wrote in message news:4CDD1C70-E791-4D63-977E-A170CDE8D098@xxxxxxxxxxxxxxxx
Hello,

What do you think about the following features:

public class GenericDecorator<T> : T
{

}

can leverage to a few things:

public interface IChannel
{
void Connect();
void Disconnect();
}

public class TcpChannel : IChannel
{
...
}

public class ChannelDescriber<T> : T where T : IChannel, class
{
public string ChannelName {get; set;}
}

another more complicated example:

public class Extender<T,K> : T
{
public K Data {get;set;}
}

which can be use to :
Extender<EventArgs,string> extender;

extender.Data (give the same ability as EventArgs<T> but more generic which can leverage other types that do not support generics.

Last is for delegates aka

delegate void extendDelegate<T,K>(K t) : T where T : delegate
// K should be added as first parameter.
and usage:

extendDelegate<ThreadStart,string> Start;

Start("hello world");

which means that even further we can do this:

System.Threading.Thread.Start(Start("ido",null)); // anonymous delegates feature

void Start(string name, object state);

you can vote for the feature in the following like:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=299676&wa=wsignin1.0
--
Best,

Ido Samuelson

.



Relevant Pages

  • Re: Feature request for C# Generic inheritence
    ... The trouble is that .NET generics, unlike C++ templates, are completely ... compile time. ... public class GenericDecorator: T ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Casting Generic Classes - Possible Solution
    ... It leaves me with the open option to use generics or not when I ... This works as saying "accept a store of anything that are Record ... public class Record { ... So I tried adding an interface into the structure: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to use generics?
    ... getting rid of the ACollection and BCollection and just having Collectionwould be a good start towards using generics to the full extent. ... public void AddCollection() ... public bool ContainsKey ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What about turbos?
    ... In Delphi.NET TSomeClasssatisfies a compile time check but ALSO ... Type checking with a cast is at runtime. ... As maybe - I haven't really thought about the .NET generics implementation as ... ensure that they get that type (or NIL as you pointed out). ...
    (borland.public.delphi.non-technical)
  • Re: .NET 2.0 to be launched on Nov 8
    ... native for generics to work. ... > and probably Delphi for Win32 RSN. ... > do when they compile a template, ...
    (borland.public.delphi.non-technical)