Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 422603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:05:51+00:00 2026-05-12T19:05:51+00:00

I thought I’d use some (what I thought was) simple generics to enforce CRUD

  • 0

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 CRUD 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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:05:52+00:00Added an answer on May 12, 2026 at 7:05 pm

    You’ve overspecified the interface. You declare T in the interface definition, but then you redeclare it in the method’s definition:

    public interface IReadable <T>  /* T is declared here */
    {
        T Read<T>(string ID); /* here, you've declare a NEW generic type parameter */
                              /* that makes this T not the same as the T in IReadable */
    }
    

    Due to this confusion, you end up with an error when you try to implement the interface.

    public class NoteAdapter : IReadable<Note> /* IReadable defines T to be Note */
    {
        public Note Read<Note>(string ID) { /* Here, you're declaring a generic parameter */
                                            /* named Note.  This name then conflicts with */
                                            /* the existing type name Note */
            return new Note();
        }
    }
    

    To fix this, you simply need to remove the generic parameter from the Read function, both in the interface, and in the NoteAdapter class:

    public interface IReadable <T>
    {
        T Read(string ID);
    }
    public class NoteAdapter : IReadable<Note>
    {
        public Note Read(string ID) {
            return new Note();
        }
    }
    

    EDIT:

    Okay, I read the rest of your post, and it seems that you’ve already discovered that this “works”, but you seem to think it’s incorrect. Why? What requirements does this not meet?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought I understood EF, particularly in terms of excrutiatingly simple CRUD, but I
Thought I understood how classes work, then I tried this code: class user {
Thought I could use the BinaryWriter but haven't had any luck. Suggestions?
I thought of the possibility of writing a Java program that could use the
I thought this would be really easy but I can't find a simple solution,
Thought I'd use an Anderson tree for something. So I started porting to C++
I thought this would be a simple thing to do with a native php
I thought it is an easy task to do, but some errors show up
I thought I knew how to use arrays until I started storing form filling
I thought that there was some way in .net 3.0 to give an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.