I thought I'd use some (what I thought was) simple generics to enforce CRUD on some Business Classes. eg.
public interface IReadable <T>
{
T Read<T>(string ID);
}
and then perhaps, I could have a NoteAdapter to do C**R**UD with the Note class eg.
public class NoteAdapter : IReadable<Note>
{
public Note Read<Note>(string ID) {
return new Note();
}
}
But for some reason, te compiler is getting confused if I have both a generic return Type and a function Parameterized with the same generic Type. That is , if I do :
public interface IReadable <T>
{
void Read<T>(string ID);
}
public class NoteAdapter : IReadable<Note>
{
public void Read<Note>(string ID) {
return new Note();
}
}
It compiles fine, although it doesnt do what I want it to ! Also, this :
public interface IReadable <T>
{
T Read (string ID);
}
public class NoteAdapter : IReadable<Note>
{
public Note Read(string ID) {
return new Note();
}
}
works fine as well, Although it too does not satisfy the requirements ! -- Why ? Because then I can't have one Class that implements a bunch of these Interfaces ..eg.
public interface IReadable <T>{
T Read (string ID);
}
public class UniversalAdapter : IReadable<Note>, IReadable<Customer> ...
{
public Note Read(string ID) {
return new Note();
}
public Customer Read(string ID) {
return new Customer();
}
}
Coz this would not compile as return types are not part of the methods signature !
I was under the impression, in C# 3.5 +
T Foo(T t);
T Foo<T> (T t);
T Foo(<SomeType> someInstance);
All have different signatures! What am I missing here ?