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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:10:01+00:00 2026-06-06T09:10:01+00:00

We can specify a derived from constraint on generic type parameters like this: class

  • 0

We can specify a “derived from” constraint on generic type parameters like this:

class Bar<T> where T : IFooGenerator

Is there a way to specify NOT derived from?


My use-case: I have a bunch of FooGenerators that are parallelizable, with the same parallelization code for each, but we don’t want them to always be parallelized.

public class FooGenerator : IFooGenerator
{
    public Foo GenerateFoo() { ... }
}

Thus, I create a generic container class for generating Foo in parallel:

public class ParallelFooGenerator<T> : IFooGenerator where T : IFooGenerator
{
    public Foo GenerateFoo()
    {
        //Call T.GenerateFoo() a bunch in parallel
    }
}

Since I want FooGenerator and ParallelFooGenerator<FooGenerator> to be interchangeable, I make ParallelFooGenerator : IFooGenerator. However, I clearly don’t want ParallelFooGenerator<ParallelFooGenerator> to be legal.

So, as an auxiliary question, is there perhaps a better way to design this if “not derived from” constraints are impossible?

  • 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-06-06T09:10:04+00:00Added an answer on June 6, 2026 at 9:10 am

    You could use something like the following:

    public interface IFooGenerator
    {
        Foo GenerateFoo();
    }
    
    interface ISerialFooGenerator : IFooGenerator { }
    
    interface IParallelFooGenerator : IFooGenerator { }
    
    public class FooGenerator : ISerialFooGenerator
    {
        public Foo GenerateFoo()
        {
            //TODO
            return null;
        }
    }
    
    public class ParallelFooGenerator<T> : IParallelFooGenerator
        where T : ISerialFooGenerator, new()
    {
        public Foo GenerateFoo()
        {
            //TODO
            return null;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a generic class like this: class MyGenericClass<T> { } On the other
In C++, a subclass can specify a different return type when overriding a virtual
Hopefully there's a solution/patch to SubSonic SimpleRepository where I can specify a column/property with
I have a some code that gets passed a class derived from a certain
Is there a way in C++ to write a concrete class which when another
I'm having trouble deciding on a way to model this type of relationship... All
From a class which does not implement Enumerator I can now create one (thks
How can you specify a common base class in .xaml files for seperate Silverlight
Can I specify the javac path from within ant, when using fork ? I'm
I'm wondering whether there is a way to find out whether a class is

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.