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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:52:06+00:00 2026-05-18T09:52:06+00:00

I guess the title doesn’t really say a lot, so here’s the explanation. I

  • 0

I guess the title doesn’t really say a lot, so here’s the explanation.

I have a parent class, which I want to hold an event Action, where T is the type of whatever child class inherits it.

e.g. something like this:

abstract class ActiveRecord
{
  protected event Action<T> NewItem;
}

class UserRecord : ActiveRecord
{
  public UserRecord()
  {
    NewItem += OnNewItem; // NewItem would in this case be Action<UserRecord>
  }

  private void OnNewItem(UserRecord obj)
  {
    // Flush cache of all users, since there's a new user in the DB.
  }
}

So the question is, is the above possible, and what would I use for T in the Parent class ?

Note that I don’t want a generic argument to my parent class, since that’d really look stupid, and thus hinder the readability.

class UserRecord : ActiveRecord<UserRecord>

I’m working on an inheritance based ORM, in case you wonder what it’s for. The NewItem event is raised whenever the ORM inserts data into the database.

Edit: Trying to clarify a bit better, with correct naming of the classes.

The ActiveRecord class resides in a separate assembly, and the UserRecord resides in a web project I’m working on. (Note: I’m the developer of both parts, however it’s two separate projects)

I want to be able to raise events upon succesfully inserting a row, deleting a row, and so forth. The events should pass the record in question as argument to the event handler, hence the need for Action.

However as I’m declaring these events in the base class (ActiveRecord), I need some way to pass the CHILD type to the event handlers, in order to get a strongly typed object.

I could of course go Action and then do a typecast in my implementation, but that really wouldn’t be very nice 🙁

Hope this clears up the question a bit, otherwise please ask 🙂

Edit 2: Just wanted to let you know reflection, dynamic methods or anything similar is an option, if that’d help. However I doubt it for this particular scenario 🙁

  • 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-18T09:52:07+00:00Added an answer on May 18, 2026 at 9:52 am

    Actually I think I just found a much better approach:

    abstract class ActiveRecord
    {
      protected virtual void OnNewItem() {}
    }
    
    class UserRecord : ActiveRecord
    {
    
      protected override void OnNewItem()
      {
        // Still got the UserRecord object, now it's just "this"
      }
    }
    

    This seems much more clean to me, so I’ll be using that instead.

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

Sidebar

Related Questions

Guess that I have a TextView that I want to update it in some
I have just launched a site (using Joomla and a custom template), which doesn't
well, the title pretty much says it all. here's a little info: i have
I'm really sure that the title of my question depicts what i mean.i guess
I am using codeigniter. I guess it doesn't matter which php framework I am
I guess some of you must have frowned eyebrows reading this title eh ?
I have the following XML file: <phonebook> <departments> <department id=1 parent= title=Rabit Hole address=
I guess the question title sums it up. Is there a time when it
As you can guess from the title, the outlining with regions finally made me
I guess my general question which I googled to no luck: Is there a

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.