VBFixedString(

  • Thread starter Thread starter Arne Garvander
  • Start date Start date
A

Arne Garvander

I have this declaration
<VBFixedString(5)> Public Comp As String

Is there a way I can programmatically retrieve my variables dimension?
 
Arne Garvander said:
I have this declaration
<VBFixedString(5)> Public Comp As String

Is there a way I can programmatically retrieve my variables dimension?

Do you mean extract the fixed size (5 in this case)? If so, then yes.

Get the MemberInfo for the member:

Dim info As MemberInfo = Me.GetType().GetMember("Comp")(0)

Get the VBFixedStringAttribute for the member:

Dim attrib As VBFixedStringAttribute = DirectCast( _
info.GetCustomAttributes(GetType(VBFixedStringAttribute), False), _
VBFixedStringAttribute() _
)(0)

Get the length from the Length property of the attribute:

Dim fixedLength As Integer = attrib.Length


HTH,
Mythran
 
Back
Top