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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:31:55+00:00 2026-05-12T14:31:55+00:00

Long story: I’m working on a system that will have Tasks and Handlers .

  • 0

Long story: I’m working on a system that will have Tasks and Handlers. Tasks will be sent from disparate parts of the system to the Handlers, where they will eventually return a value.

We’ve got a system in-place that is loosely-typed and has turned into something of a gnarled mess (the problem is significantly amplified by the fact that the task-initiators are often coming from third-party components that are essentially plug-ins).

I’ve been thinking of ways to implement the same in a strongly-typed fashion–and might just be taking this to the point of obsurdity–but am close to what I’d like. The problem is some syntax.

Here’s what I’ve got (generic names expanded for clarity):

interface ITask<ReturnType> { }

interface ITaskHandler<TaskType, TaskReturnType> where TaskType : ITask<TaskReturnType>
{
    TaskReturnType PerformTask(TaskType task);
}

As you can see, ITask is generic, and the declared generic parameter for ITask is the return-type for ITaskHandler<ITask>. This means that each TaskHandler is contractually bound to return the type specified by its ITask.

The big downside that declaring TaskHandlers leads to some fairly ugly Signatures…

class SpecificTask : ITask<Dictionary<Type,Delegate>>
{
}

class SpecificHandler : ITaskHandler<SpecificTask, Dictionary<Type, Delegate>>
{
    public Dictionary<Type, Delegate> PerformTask(SpecificTask task)
    {
        return new Dictionary<Type, Delegate>();
    }
}

My question is: since SpecificTask has already provided it’s ReturnType as a generic parameter, can SpecificHandler‘s signature be shortened to something more like:

interface ITaskHandler<TaskType> where TaskType : ITask
{
    // pulling TaskReturnType out of thin air...
    TaskReturnType PerformTask(TaskType task);
}

class SpecificHandler : ITaskHandler<SpecificTask>
{
    public Dictionary<Type, Delegate> PerformTask(SpecificTask task)
    {
        return new Dictionary<Type, Delegate>();
    }
}

…and if so, how would I declare the return type of PerformTask when the type is contained within SpecificTask?

  • 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-12T14:31:55+00:00Added an answer on May 12, 2026 at 2:31 pm

    Unfortunately you can’t do what you want to do and retain static type checking. All of the generic type parameters must be delared in order for the compiler to be able to statically know what goes where.

    You could do this with reflection but that would completely undermine the purpose of generics in the first place.

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

Sidebar

Related Questions

Long story short: We've got a system that we're moving from one server to
Long story short: I have some controller logic that requests a value from the
Long story short, I have a struct (see below) that contains exactly one field:
Long story short, I have a SQL file that I want to import as
Long story short, I'm working on a .NET profiler that at one point gets
Long story short, I have two regex patterns. One pattern matches things that I
Long story short, I have a long code that uses jQuery. Lots of files,
Long story short, I have a substantial Python application that, among other things, does
Long story short -- we have 2 webservers that run a 3rd party asp.net
Long story short I'm working with a legacy codebase that makes heavy use of

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.