views:

70

answers:

2

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?

EDIT: only for the example I used directly GetType(UInt16) but in real code this part is substituted by an instance of unknown-at-design-time .NET Type

A: 

It's not a Property it's a constant...

Any reason you can't just call?: Integer.MaxValue Integer.MinValue

eschneider
I added more details why I cannot use it
marco.ragogna
+2  A: 

Use GetType.GetField("MinValue"). Constants are considered Fields

M.A. Hanin
omg, such a noob I am :D too much stress. Thank you!
marco.ragogna
We're all noobs (Skeet excluded), make yourself comfortable.
M.A. Hanin
Sometimes you just need a different set of eyes...
eschneider
@eschneider your are right! this is also one of the reason why I like this place, I can go and take a coffee and when I come back most of times I find an helpful answer
marco.ragogna