Click here to Skip to main content
15,895,142 members
Articles / Programming Languages / C#

Parameters Flexibility When Late Binding to an Event

Rate me:
Please Sign up or sign in to vote.
3.57/5 (6 votes)
20 Jun 2011CPOL7 min read 21.9K   115   14  
.NET allows binding to an event with a method that has a different signature than that of the published delegate, as long as the return type and the parameter types are derived from those in the published delegate. This article offers a mechanism for allowing this flexibility when late binding to an
  • EventLateBindingHelper.zip
    • EventLateBindingHelper
      • EventLateBindignHelper.Test
      • EventLateBindingHelper.sln
      • EventLateBindingHelper.vsmdi
      • EventLateBindingHelper
      • Local.testsettings
      • TestResults
        • Asher_ASHER-PC 2011-05-29 14_14_41.trx
        • Asher_ASHER-PC 2011-05-29 14_14_41
          • In
            • ASHER-PC
          • Out
            • AgentRestart.dat
        • Asher_ASHER-PC 2011-05-29 14_17_01.trx
        • Asher_ASHER-PC 2011-05-29 14_17_52.trx
        • Asher_ASHER-PC 2011-05-29 14_19_26.trx
        • Asher_ASHER-PC 2011-05-29 14_19_35.trx
        • Asher_ASHER-PC 2011-05-29 14_19_47.trx
        • Asher_ASHER-PC 2011-05-29 14_19_47
          • In
            • ASHER-PC
          • Out
            • AgentRestart.dat
        • Asher_ASHER-PC 2011-05-30 10_39_04.trx
        • Asher_ASHER-PC 2011-05-30 10_39_54.trx
        • Asher_ASHER-PC 2011-05-30 11_10_36.trx
        • Asher_ASHER-PC 2011-05-30 11_12_47.trx
        • Asher_ASHER-PC 2011-05-30 12_09_20.trx
        • Asher_ASHER-PC 2011-05-30 12_09_39.trx
        • Asher_ASHER-PC 2011-05-30 12_09_39
          • In
            • ASHER-PC
          • Out
            • AgentRestart.dat
        • Asher_ASHER-PC 2011-05-30 13_03_56.trx
        • Asher_ASHER-PC 2011-05-30 13_04_13.trx
        • Asher_ASHER-PC 2011-05-30 13_04_13
          • In
            • ASHER-PC
          • Out
            • AgentRestart.dat
        • Asher_ASHER-PC 2011-05-30 13_05_54.trx
        • Asher_ASHER-PC 2011-05-30 14_12_54.trx
        • Asher_ASHER-PC 2011-05-30 14_13_12.trx
        • Asher_ASHER-PC 2011-05-30 14_13_42.trx
        • Asher_ASHER-PC 2011-05-30 14_14_37.trx
        • Asher_ASHER-PC 2011-05-30 14_17_42.trx
        • Asher_ASHER-PC 2011-05-30 14_17_42
          • In
            • ASHER-PC
          • Out
            • AgentRestart.dat
        • Asher_ASHER-PC 2011-05-30 14_18_21.trx
        • Asher_ASHER-PC 2011-05-30 14_20_13.trx
        • Asher_ASHER-PC 2011-05-30 14_21_53.trx
        • Asher_ASHER-PC 2011-05-30 14_30_08.trx
        • Asher_ASHER-PC 2011-05-30 14_37_36.trx
      • TraceAndTestImpact.testsettings
  • EventLateBindingHelper.zip
    • _ReSharper.EventLateBindingHelper
      • BuildScriptCache
      • EventLateBindingHelper.5.1.ReSharper.user
      • EventLateBindingHelper.sln
      • EventLateBindingHelper.sln.docstates
      • EventLateBindingHelper.vsmdi
      • EventLateBindingHelper.dll
      • DelegateGenerator.cs
      • EventLateBindingHelper.csproj
      • AssemblyInfo.cs
      • Local.testsettings
      • Asher_ASHER-PC 2011-05-29 14_19_35.trx
      • Asher_ASHER-PC 2011-05-29 14_19_47.trx
      • AgentRestart.dat
      • Asher_ASHER-PC 2011-05-30 10_39_04.trx
      • Asher_ASHER-PC 2011-05-30 10_39_54.trx
      • Asher_ASHER-PC 2011-05-30 11_10_36.trx
      • Asher_ASHER-PC 2011-05-30 11_12_47.trx
      • Asher_ASHER-PC 2011-05-30 12_09_20.trx
      • Asher_ASHER-PC 2011-05-30 12_09_39.trx
      • AgentRestart.dat
      • Asher_ASHER-PC 2011-05-30 13_03_56.trx
      • Asher_ASHER-PC 2011-05-30 13_04_13.trx
      • AgentRestart.dat
      • Asher_ASHER-PC 2011-05-30 13_05_54.trx
      • Asher_ASHER-PC 2011-05-30 14_12_54.trx
      • Asher_ASHER-PC 2011-05-30 14_13_12.trx
      • Asher_ASHER-PC 2011-05-30 14_13_42.trx
      • Asher_ASHER-PC 2011-05-30 14_14_37.trx
      • Asher_ASHER-PC 2011-05-30 14_17_42.trx
      • AgentRestart.dat
      • Asher_ASHER-PC 2011-05-30 14_18_21.trx
      • Asher_ASHER-PC 2011-05-30 14_20_13.trx
      • Asher_ASHER-PC 2011-05-30 14_21_53.trx
      • Asher_ASHER-PC 2011-05-30 14_30_08.trx
      • Asher_ASHER-PC 2011-05-30 14_37_36.trx
      • Asher_ASHER-PC 2011-05-31 09_13_21.trx
      • Asher_ASHER-PC 2011-06-20 15_54_53.trx
      • Asher_ASHER-PC 2011-06-20 15_55_49.trx
      • Asher_ASHER-PC 2011-06-20 15_58_43.trx
      • TraceAndTestImpact.testsettings
    • ExceptionCreatingDelegateWithWrongMethodSigniture.PNG
    • ParametersFlexibilityWhenLateBindingToAnEvent.htm
    • ParametersFlexibilityWhenLateBindingToAnEvent_v2.htm
    • ParametersFlexibilityWhenLateBindingToAnEvent_v2_files
      • CodeProject.css
      • ExceptionCreatingDelegateWithWrongMethodSigniture.PNG
      • WrongDelegateTypeAssignment.png
    • WrongDelegateTypeAssignment.PNG
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EventLateBindignHelper.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EventLateBindignHelper.Test")]
[assembly: AssemblyCopyright("Copyright ©  2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9de9dd24-6061-45a0-a3c0-b63a97878920")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Ziv systems, Israel
Israel Israel
Starting with Apple IIe BASICA, and working my way through Pascal, Power Builder, Visual basic (and the light office VBA) C, C++, I am now a full stack developer and development manager. Mostly with MS technologies on the server side and javascript(typescript) frameworks on the client side.

Comments and Discussions