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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:14:02+00:00 2026-05-11T04:14:02+00:00

I have a set of some classes which are all capable of being constructored

  • 0

I have a set of some classes which are all capable of being constructored with an argument being an instance of a particular interface. Since they all can be constructed by this same object (and the process during which this construction happens is largely the same in all cases), I figured perhaps templating would work. Basically, I want to do something like this:

public static void dostuff<T, U> (List<T> items) {     foreach (T item in items)     {         func(new U(item).SpecialMember);     } } 

Of course, that won’t compile since U is templated and thus lacks SpecialMember as well as the T constructor.

Basically, any given implementation of the inteface T has certain features. U is an implementation of T which has an additional feature that is needed *and* which can be constructed from an any instance ofU`.

Advice?

  • 1 1 Answer
  • 3 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. 2026-05-11T04:14:03+00:00Added an answer on May 11, 2026 at 4:14 am

    Unfortunately while constraints will get you some of the way there, there’s no way to specify that a type has a constructor which takes certain argument: the only constructor you can require is a parameterless one.

    Personally I’d like to see that change using an idea of ‘static interfaces’ (only usable for type constraints) but for the moment the best you’ll get is a type factory or reflection – or possibly a parameterless constructor and an ‘Init’ method in the interface. None of these are nice options, frankly.

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

Sidebar

Related Questions

I have some classes that all implement the same Java interface, which essentially allows
I have a set of classes, each of which need to decide at some
I have one AlertDialog which is working fine.I have set some background images to
I have to set some routing rules in my php application, and they should
I have a set of classes which extend an abstract class. The abstract class
I have a common base class from which all my ASMX webservice classes will
I have a Device interface: public interface IDevice { double Measure(); } Some classes
I'm making some controls which all have to share the same look and some
I have a set of related C++ classes which must be wrapped and exported
I'm testing with EF 4.3 (beta) I have some new classes which should generate

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.