Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

2 Classes that share same event handlers

$
0
0

Is it possible to have 2 classes that are slightly different but have the same event handlers?  The classes are quite large and there are quite a few EventHandlers.  Instead of having duplicate copies of EventHandlers in each class, I was wondering if there was a way to put them in a "separate class" so if I have to add or edit the event handlers I can do it in one class?

public class MyFirstClass
{
	...

	public event EventHandler<tblCa> CaDataReceived;
        private void RaiseCaDataReceived(tblCa args)
        {
            if (CaDataReceived != null)
            {
                CaDataReceived(this, args);
            }
        }

	// About 15 more Handlers just like one above

}

public class MySecondClass
{
	...

	public event EventHandler<tblCa> CaDataReceived;
        private void RaiseCaDataReceived(tblCa args)
        {
            if (CaDataReceived != null)
            {
                CaDataReceived(this, args);
            }
        }

	// About 15 more Handlers just like one above
	// Exactly the same as the ones in MyFirstClass

}

// Posibbly this:
public class MyClassEventHandlers
{
	public event EventHandler<tblCa> CaDataReceived;
        private void RaiseCaDataReceived(tblCa args)
        {
            if (CaDataReceived != null)
            {
                CaDataReceived(this, args);
            }
        }
}
Thanks


Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>