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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:22:05+00:00 2026-05-11T06:22:05+00:00

I’m writing my custom events in C++/CLI (I pretty much only care about the

  • 0

I’m writing my custom events in C++/CLI (I pretty much only care about the add/remove methods) as such:

    event EventHandler<XyzEventArgs^> ^Xyz     {         void add(EventHandler<XyzEventArgs^> ^handler);         void remove(EventHandler<XyzEventArgs^> ^handler);         void raise(Object ^sender, XyzEventArgs ^e);     } 

Everything works great, but when I look at Intellisense under C#, it shows an ugly-looking public raise_Xyz method.

Any ideas on how to hide that without making my events private?

Any help greatly appreciated.

EDIT:

I was able to eliminate the public raise_Xyz methods by marking them with a different visibility modifier (internal in my case). This pretty much means that the events cannot be raised from outside of the class. That’s fine with me. I have noticed, however, that even simple events

public: event EventHandler ^XXX; 

generate raise_XXX methods and they are protected. Is there any way of preventing that from happening?

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T06:22:05+00:00Added an answer on May 11, 2026 at 6:22 am

    note that this is true for the ECMA-372 specification. c# 4 changes the event mechanism scaffold created by the compiler so the C++/CLI ones may also change

    Because the events are handled by the compiler generating the relevant scaffold (or allowing you to do your own scaffold for them) there will, by necessity, be a bunch of methods generated to do this.

    C++/CLI differs from most other .Net languages in that it’s event sugar allows sub classes to raise events declared on the base class.

        public ref class Class1     {     public:         event EventHandler^ MyEvent;     };      public ref class Class2 : Class1     {     public:         void Foo()         {             this->MyEvent(this, gcnew System::EventArgs());         }     }; 

    This compiles (and runs) just fine. compare to c# equivalent

        public class Class1     {         public event EventHandler MyEvent;     }      public class Class2 : Class1     {         public void Foo()         {         base.MyEvent(this, new System::EventArgs());         }     } 

    which will refuse to compile saying:

    The event ‘Class1.MyEvent’ can only appear on the left hand side of += or -= (except when used from within the type ‘Class1’)

    For C++/CLI to do this it must expose the raise_Xxx method as protected. Exposing the underlying delegate field which maintains the event by default would be dangerous as well as disallowing the flexibility of a class to implement events its own way without an automatic delegate backing field.

    If you don’t want subclasses to be able to do this (or see it) then making it internal is an effective solution for code which is outside the assembly.

    note that the C++ CLI spec defines the naming convention for the event scaffolding

    18.2.2 Member names reserved for events

    For an event E (§18.5), the following names are reserved:

    • add_E
    • remove_E
    • raise_E

    So this is not something which can be changed

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am writing an app with both english and french support. The app requests
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.