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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:15:56+00:00 2026-06-11T16:15:56+00:00

In .NET applications, normally events are wired this way: public event EventHandler<ChangeEventArgs> OnChange {

  • 0

In .NET applications, normally events are wired this way:

    public event EventHandler<ChangeEventArgs> OnChange
    {
        add { _dependency.OnChange += value; }
        remove { _dependency.OnChange -= value; }
    }

However this only works if the events being wired have the same event handler. In my current case, the original event args is proprietary of a library, and I don’t want to expose that to the client code. So I have some kind of adapter (ChangeEventArgs). How can I use the code above to convert the event args? I imagine something like below (but below code doesn’t work)

    public event EventHandler<ChangeEventArgs> OnChange
    {
        add { _dependency.OnChange += Convert(value); }
        remove { _dependency.OnChange -= Convert(value); }
    }

or

    public event EventHandler<ChangeEventArgs> OnChange
    {
        add { _dependency.OnChange += value(this, Convert(args)); }
        remove { _dependency.OnChange -= value(this, Convert(args)); }
    }
  • 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-11T16:15:58+00:00Added an answer on June 11, 2026 at 4:15 pm

    Try this:

    public class SomeClassAdapter
    {
        private readonly SomeClass obj;
    
        public SomeClassAdapter(SomeClass obj)
        {
            this.obj = obj;
            this.obj.SomeEvent += HandleSomeClassSomeEvent;
        }
    
        private void HandleSomeClassSomeEvent(object sender, SomeEventArgs args)
        {
            OnSomeEvent(ConvertEventArgs(args));
        }
    
        private MyEventArgs ConvertEventArgs(SomeEventArgs args)
        {
            // the magic goes here...
        }
    
        protected virtual void OnSomeEvent(MyEventArgs args)
        {
            var handler = SomeEvent;
            if (handler != null)
            {
                handler(this, args);
            }
        }
    
        public event EventHandler<MyEventArgs> SomeEvent;
    }
    

    Update.
    This code uses more complex version of adapter pattern, than your code does. SomeClassAdapter is an adapter for SomeClass (it has SomeClass instance in its private field obj).

    Client code subscribes to my SomeClassAdapter.SomeEvent. My code, in turn, subscribes to SomeClass.SomeEvent. When SomeClass.SomeEvent is fired, my event handler (HandleSomeClassSomeEvent) is called. This event handler converts SomeEventArgs to MyEventArgs and raises SomeClassAdapter.SomeEvent.

    So, we have the chain: SomeClass.SomeEvent -> HandleSomeClassSomeEvent -> SomeClassAdapter.SomeEvent. Looks like “event proxy”.

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

Sidebar

Related Questions

There are several scripting environments available for .NET applications (e.g. this post ). My
I'll preface this by saying that I usually work in C#/.Net. Normally, I use
For my VB.NET applications, I am wanting the user to have a free trial
I have two .NET applications that talk to each other over a named pipe.
We are developing .net applications and using Clearcase for our SCM needs. We have
We have some Microfocus Cobol.Net applications. We would like to create a dependency map
I have two Visual Studio vb.NET applications. Previously, I have published each application separately
When applying the MVP pattern to ASP.NET applications, where does using AJAX to post
I want to make existing .NET applications (WinForms and WebForms) run on 64-bit machines,
I have intranet highly user interactive ASP.net applications, which now I am going to

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.