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

  • Home
  • SEARCH
  • 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 6861697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:34:05+00:00 2026-05-27T02:34:05+00:00

Resharper has suggested to change from interface IModelMapper<TFrom, TTo> { TTo Map(TFrom input); }

  • 0

Resharper has suggested to change from

interface IModelMapper<TFrom, TTo>
{
    TTo Map(TFrom input);
}

into

interface IModelMapper<in TFrom, out TTo>

So I investigate a little and ended reading this article (found through a Wikipedia article) and some more Google.

I am still not sure what this would imply for my application so I am tempted of not accepting the suggestion. What would are the benefits this change would introduce and I am not considering by ignoring the suggestion?

More explicitly, why should I accept it?

  • 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-27T02:34:06+00:00Added an answer on May 27, 2026 at 2:34 am

    Bottom Line: Resharper has investigated your type, and discovered that TFrom may be used contravariantly, and TTo covariantly. Accepting the refactor would allow you to use these types with greater flexibility, as described below. If that might be of value to you, accept it.

    Note, however, that accepting this refactor would place restrictions on how you use these types in the future. If you ever write a method that takes TTo as a parameter, you’ll get a compiler error, since coviariant types cannot be read in. And ditto for TFrom: you’ll never be able to have a method that returns this type, or has an out parameter of this type.


    That’s telling you that TFrom is contravariant, and that TTo is covariant. These were features recently added to C#

    Type covariance means that a more specific type may be passed in, while contravariance means that a less specific type may be passed in.

    IEnumerable<T> is a good example of type covariance. Since items in an IEnumerable<T> are read only, you may set it to something more specific:

    IEnumerable<object> objects = new List<string>();
    

    Consider what could happen if (hypothetically) you were allowed to do this for collections that were read/write:

    List<object> objects = new List<string>();
    objects.Add(new Car());
    //runtime exception
    

    To be type covariant, a generic parameter must be used in a strictly read-only manner; it must only ever be written out from the type, and never read in (hence the keywords). That’s why the IEnumerable<T> example works, but the List<T> example doesn’t. By the way, arrays do support type covariance (since Java does, I believe), and so this same kind of runtime error is possible with arrays.

    Type contravariance means the opposite. To support type contravariance a generic parameter must be read in only, and never written out. This allows you to substitute less specific types in.

    Action<T> is an example of type contravaince:

    Action<object> objAction = (o => Console.WriteLine(o.ToString()));
    Action<string> strAction = objAction;
    strAction("Hello");
    

    strAction is declared to take a string parameter, but it works fine if you substitute an object type. A string will be passed in, but if the delegate it’s set to work with chooses to treat it as an object, then so be it. No harm done.

    For completeness, Func<T> is the inverse case of Action<T>; here T is only returned, therefore it’s covariant:

    Func<string> strDelegate =  () => "Hello";
    Func<object> myObjFunc = strDelegate;
    object O = myObjFunc();
    

    myObjectFunc is coded to return an object. If you set it to something that returns a string, then, again, no harm done.

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

Sidebar

Related Questions

I've just checked out a solution from Subversion and ReSharper is telling me it
Recently, my Visual Studio 2008(with Resharper 4.5) has started to reformat asp tags into
Using Resharper, I extracted an interface of an existing class. This class has some
Resharper (paired with StyleCop) has made me a bit of a neat freak when
Recenty I installed ReSharper 4.5. It has a cool new feature of checking naming
Resharper certainly thinks so, and out of the box it will nag you to
ReSharper likes to point out multiple functions per ASP.NET page that could be made
I just purchased a license to ReSharper 5.0 and it has been almost impossible
I don't want resharper to analyze my Test Project which has all my unit
I wanted to know if anyone has worked out how to disable the Public

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.