abstract references to generic interfaces
Does anyone else feel that it might be useful if the runtime allowed references to members of a generic interface that were not specific to the generic type? I know the usual "workaround" is to create a non-generic interface as the base for the generic interface, but is there a valid reason against that base interface basically being automatic?
For example, given the following interface:
public interface IProcessor<T>
{
string Name { get; }
void Process(T item);
}
I think it would be convenient to automatically allow something like this:
public void LogProcessor(IProcessor<> item)
{
Trace.WriteLine(item.Name);
}
I'm curious to hear 开发者_StackOverflow社区arguments against this (other than "stop being so lazy and just write the base interface").
You can just use a generic method:
public void LogProcessor<T>(IProcessor<T> item)
{
Trace.WriteLine(item.Name);
}
The main reason why not is common language specification. And add such stuff is a big part of work and testing for microsoft framework developers. So its more easy is add base interface. But anyway you can post you idea to microsoft forums
精彩评论