I have code a bit like this
public class MyObject
{
private bool IsValidDay(ref DateTime theDate)
{
...
}
}
MethodInfo[] methods = myObjectInstance.GetType().GetMethod("IsValidDay", BindingFlags.Instance | BindingFlags.NonPublic);
object[] args = { null };
bool val = (bool)method.Invoke(myObjectInstance, args);
But when the method is called, from within the IsValidDay method, theDate is DateTime.MinValue. This seems awfully weird - I'd perhaps expect a NullReferenceException to be thrown but not an automatic conversion.
In case you are wondering, this is code in a unit test. (in use the method is typically called via a public method that takes object).
As far as some other code which is subsequently called is concerned, DateTime.MinValue and null are not the same thing, so it's a little bit of a problem.
Any clues?? Suggestions.