How to get MinValue/MaxValue of a certain ValueType via reflection?

Posted by marco.ragogna on Stack Overflow See other posts from Stack Overflow or by marco.ragogna
Published on 2010-03-31T15:19:50Z Indexed on 2010/03/31 15:23 UTC
Read the original article Hit count: 366

Filed under:
|

I need to this at runtime. I checked using Reflector and value types line like Int16, for example, should contain

<Serializable, StructLayout(LayoutKind.Sequential), ComVisible(True)> _
Public Structure Int16
    Implements IComparable, IFormattable, IConvertible, IComparable(Of Short), IEquatable(Of Short)

Public Const MaxValue As Short = &H7FFF
Public Const MinValue As Short = -32768


End Structure

But the following code is not working

Dim dummyValue = Activator.CreateInstance(GetType(UInt16))
Dim minValue As IComparable =    DirectCast(dummyValue.GetType.GetProperty("MinValue").GetValue(dummyValue,
Nothing), IComparable)

any idea how to solve?

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about reflection