http://www.codinghelmet.com/  

Wear a helmet. Even when coding.

net > sysexpand > reflection > manual > intro

Introduction
by Zoran Horvat @zoranh75

When handling a CLR event raised by a .NET object caller must know signature of the event handler at compile time or otherwise there is no regular way to subscribe to the event. This can be a serious problem in some applications where event handler signature is not known in advance. These applications are very rare in practice but every programmer sometimes encounters such a problem. There is no general solution to the problem available at compile time. Instead of finding approximate solutions (like allowing handling of events from only a limited set of supported handler signatures, like the one proposed by EventHandler delegate type) we can solve the problem at run time when particular event handler signature becomes known.

SysExpand.Reflection namespace provides a fully functional solution to the problem of general CLR event handling in .NET applications. Classes provided are capable to subscribe to events no matter of their actual signature and to handle all events and pass them on in the form of an event with quite general signature. In this way, applications can handle that single event and then process its arguments to find all details provided by the original event which was unknown at compile time.

See also:

Published: Feb 11, 2012; Modified: Apr 14, 2013

ZORAN HORVAT

Zoran is software architect dedicated to clean design and CTO in a growing software company. Since 2014 Zoran is an author at Pluralsight where he is preparing a series of courses on object-oriented and functional design, design patterns, writing unit and integration tests and applying methods to improve code design and long-term maintainability.

Follow him on Twitter @zoranh75 to receive updates and links to new articles.

Watch Zoran's video courses at pluralsight.com (requires registration):

Making Your C# Code More Object-Oriented

This course will help leverage your conceptual understanding to produce proper object-oriented code, where objects will completely replace procedural code for the sake of flexibility and maintainability. More...

Advanced Defensive Programming Techniques

This course will lead you step by step through the process of developing defensive design practices, which can substitute common defensive coding, for the better of software design and implementation. More...

Tactical Design Patterns in .NET: Creating Objects

This course sheds light on issues that arise when implementing creational design patterns and then provides practical solutions that will make our code easier to write and more stable when running. More...

Tactical Design Patterns in .NET: Managing Responsibilities

Applying a design pattern to a real-world problem is not as straight-forward as literature implicitly tells us. It is a more engaged process. This course gives an insight to tactical decisions we need to make when applying design patterns that have to do with separating and implementing class responsibilities. More...

Tactical Design Patterns in .NET: Control Flow

Improve your skills in writing simpler and safer code by applying coding practices and design patterns that are affecting control flow. More...

Writing Highly Maintainable Unit Tests

This course will teach you how to develop maintainable and sustainable tests as your production code grows and develops. More...

Improving Testability Through Design

This course tackles the issues of designing a complex application so that it can be covered with high quality tests. More...

Share this article

webmasters