Friday, May 9, 2014

When testing static methods in a static class in C# via reflection, you may just hand in null for the first Invoke parameter.

The second parameter will still populate the parameters in the method signature with its array contents.

Type type = typeof(MyStaticType);
MethodInfo info = type.GetMethods(BindingFlags.NonPublic|BindingFlags.Static)[0];
Expectations[] expectations = (Expectations[])info.Invoke(null, new object[] { "x", "y" });
Assert.AreEqual(expectations.Length, 999);

No comments:

Post a Comment