O'Reilly logo

C# Primer: A Practical Approach by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required