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 959573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:02:56+00:00 2026-05-16T01:02:56+00:00

I have created a generic method that enables clients to specify both the concrete

  • 0

I have created a generic method that enables clients to specify both the concrete type of the returned instance and the actual returned type (e.g. an interface) as independent type parameters. Naturally, the concrete returned instance type parameter is constrained to inherit from the actual returned type.

The idea is that you may return an interface from the IFactory (an object factory) Create method. The spur for this madness was that AutoMapper needs to know which concrete type to instantiate in the factory create method, and I’d rather define the factory return value in terms of an interface.

Unfortunately you end up with quite a ridiculously long method signature.

Code:

public static TDestinationBase 
  MapToDomain<TSource, TDestinationBase, TDestination>
    (this TSource source, IFactory<TSource, TDestinationBase> factory) 
      where TSource : IMappable<TDestination>, IDto 
      where TDestination : TDestinationBase
    {
        return factory.Create<TDestination>(source);
    }

If anyone can understand all this, I wonder if anyone has anything they can share regarding the separation of concrete type from returned type in generic interfaces, and whether this is at all a worthwhile endeavor.

  • 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-16T01:02:57+00:00Added an answer on May 16, 2026 at 1:02 am

    I’m pretty sure I understand it, but I’m not sure it’s worth doing. Does it provide much benefit over just casting to the interface (or assigning to a variable of the interface type) at the calling side? I suppose it encourages you to think about using an interface instead of the concrete type… but it’s still not going to enforce that: the caller could just specify the same type twice.

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

Sidebar

Related Questions

I have a method that given a delegate Type argument (not a generic), it
I have created a subclass of a generic list so that I could implement
I have created a Generic Extension method for DataRow object. The method takes no
Say I have a method that is expecting a generic collection parameter of a
I have created a universalrepository that takes the type passed to it and when
Hi i have created a Generic Array that works fine for Int,String, Float or
Good Morning, I have created my first generic method pieced together from a bunch
I have created a mini installer in NSIS that installs patches for my application.
I have two separate views that both show multiple lists of values. Both views
I have a method that counts the number of Contacts each Supplier, Customer and

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.