VS2010 Implementation of a universal interface does not use the specified type

Using the version of Visual Studio 2010 release, I believe that the difference in the "Implementation Interface" extension from VS2008

If I explain the interface and implement it in the class like this:

public interface IRepository<T> where T : IModel
{
    T Get<T>(int id);
    void Update<T>(T item);
    int Add<T>(T item);
}    

public class MockRepository : IRepository<MockUser>
{
// ...
}

Then use the "Implementation Interface" extension and get the following:

public class MockRepository : IRepository<MockUser>
{
    public T Get<T>(int id)
    {
        throw new NotImplementedException();
    }

    public void Update<T>(T item)
    {
        throw new NotImplementedException();
    }

    public int Add<T>(T item)
    {
        throw new NotImplementedException();
    }
}

Instead of what I expected

public class MockRepository : IRepository<MockUser>
{
    public MockUser Get<MockUser>(int id)
    {
        throw new NotImplementedException();
    }

    public void Update<MockUser>(MockUser item)
    {
        throw new NotImplementedException();
    }

    public int Add<MockUser>(MockUser item)
    {
        throw new NotImplementedException();
    }
}

The IDE uses the name of a type variable from the common interface definition Tinstead of the specified concrete type MockUser. This is mistake? Or is there something new for VS2010 / .Net 4.0?

Update: This is NOT a mistake, I did not specify the interface as I wanted, it should be defined as:

public interface IRepository<T> where T : IModel
{
    T Get(int id);
    void Update(T item);
    int Add(T item);
}    

In other words, I did not need to specify the type parameter Tat the interface and method level, but only at the interface.

+3
2

<T> . , , - , :

public class MockRepository : IRepository<IModel>
{
    public IModel Get(int id)
    {
        throw new NotImplementedException();
    }

    public void Update()
    {
        throw new NotImplementedException();
    }

    public int Add(IModel item)
    {
        throw new NotImplementedException();
    }
}

/. , IModel . ( , T in IRepository<T> T Get<T>.)

+4

, .

T, , . T .

+4

Source: https://habr.com/ru/post/1741210/


All Articles