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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:49:51+00:00 2026-05-30T23:49:51+00:00

I’m trying to create an event delegate where the parameter is strongly typed to

  • 0

I’m trying to create an event delegate where the parameter is strongly typed to match the current class, like this:

public class HPCRequest
{
    public delegate void RequestCompleteHandler(HPCRequest request);
    public event RequestCompleteHandler RequestComplete;

The problem is that the point of this class is to be inherited, and what I really want is for all those inheriting classes to have the “RequestComplete” event, where the delegate is typed for that class:

public class HPCGetConfig : HPCRequest
{
    //I want this class to effectively inherit something like this:
    //public delegate void RequestCompleteHandler(HPCGetConfig request);

This is because currently, when I have a function that handles one of my “RequestComplete” events, I currently have to do this:

    myGetConfigRequest.RequestComplete += new HPCRequest.RequestCompleteHandler(HPCGetExpectedLosses_RequestComplete);

void HPCGetConfig_RequestComplete(HPCRequest request)
{
    HPCGetConfig thisRequest = request as HPCGetConfig;
    //This should be strongly typed in the first place.

But I want to be able to do something like this:

    request.RequestComplete += new HPCGetConfig.RequestCompleteHandler(HPCGetConfig_RequestComplete);
    request.SendRequestAsync();
}

void HPCGetConfig_RequestComplete(HPCGetConfig request)
{
    request.RequestComplete -= HPCGetConfig_RequestComplete;

Attempts

I’ve tried this:

public delegate void RequestCompleteHandler<T>(T request) where T : HPCRequest; 
public event RequestCompleteHandler<T> RequestComplete;

but when I try to invoke the event from within the base class using RequestComplete(this);, I get a compile time error: `Delegate ‘RequestCompleteHandler’ has some invalid arguments.

This happens whether or not I set up the entire HPCRequest class as HPCRequest<T> by going:

public class HPCRequest<T> where T : HPCRequest<T> 
{
    public delegate void RequestCompleteHandler<T>(T request); 
    public event RequestCompleteHandler<T> RequestComplete;

public class HPCGetConfig : HPCRequest<HPCGetConfig> { ...

The same error occurs when I try to invoke the event: RequestComplete(this);

 

I’ve also tried all forms of creating the delegate and event and overriding them, such as in doing:

public class HPCRequest
{
    public delegate void RequestCompleteHandler(HPCRequest request);
    public virtual event RequestCompleteHandler RequestComplete;


public sealed class HPCGetConfig : HPCRequest
{
    public delegate void RequestCompleteHandler(HPCGetConfig request);
    public override event RequestCompleteHandler RequestComplete;

But this gives me a compile time error because I cannot override the RequestComplete event with one of a different delegate type.

Any other ideas?


Edit

Templating the entire HPCRequest class is not an option, after a very thorough attempt, I see that it just screws up every attempt to use the type HPCRequest as a placeholder for any request type. If this solution is going to work, the class HPCRequest must be able to be instantiated and inherited from without specifying a type parameter. I’ll need a solution that doesn’t require templating HPCRequest.

To make sure everyone know exactly how I’m trying to use this, I pasted some sample code into pastebin that should let you experiment with ways of getting this event templating working without breaking anything. Here it is: http://pastebin.com/bbEYgLj1

  • 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-30T23:49:52+00:00Added an answer on May 30, 2026 at 11:49 pm

    It’s can’t be done.

    I’ve ended up having to cast the delegate everywhere it’s used.

    Happy to change the accepted answer if anything ever shows otherwise.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,

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.