8.5. Delegating the Test to Reflection

In the introduction to the delegate type in Section 2.12, there is a brief discussion of a testHarness class. testHarness maintains a static delegate member in which other classes register test functions they wish executed. It looks like this:

public delegate void Action();
public class testHarness
{
    static private Action theAction;
    static public Action Tester
         { get{ return theAction;  }
           set{ theAction = value; }}
    static private void reSet() { theAction = null; }
    static public  int  count()
         { return theAction != null
                ? theAction.GetInvocationList().Length : 0; }
    // ...
}

By convention, a class wishing to register one or more member functions with Tester does so within the static constructor of the class—for ...

Get C# Primer: A Practical Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.