VS2010 Implement Generic Interface expansion doesn't use specified type

Posted by TJB on Stack Overflow See other posts from Stack Overflow or by TJB
Published on 2010-04-15T05:52:26Z Indexed on 2010/04/15 6:13 UTC
Read the original article Hit count: 319

Using the release version of Visual Studio 2010 I think there's a difference in the "Implement Interface" expansion from VS2008

If I speicify an interface and implement it in a class as so:

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

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

Then use the "Implement Interface" expansion and get this:

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

    public void Update<T>()
    {
        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>()
    {
        throw new NotImplementedException();
    }

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

The IDE uses the type variable name from the generic interface definition T instead of the specified concrete type MockUser. Is this a bug? Or is something new just for VS2010 / .Net 4.0?

© Stack Overflow or respective owner

Related posts about c#

Related posts about visual-studio-2010