I am trying to call the public TryParse method via a dynamic object but I am getting a RuntimeBinderException... "System.Reflection.TypeInfo does not contain a definition for TryParse". The dynamic object at runtime has type System.Boolean and this class has that public method defined.
Note. Reason for this is to create a generic TryParse method with additional error checking that will be used repeatedly through the application.
Here's the code to reproduce the problem:
private (bool Success, T Value) TryParse<T>(string strval)
{
(bool Success, T Value) retval;
dynamic dtype = typeof(T);
retval.Success = dtype.TryParse(strval, out retval.Value);
return retval;
}
In my case, I am testing the method with TryParse("true"). What am I doing wrong? Thanks.