Advertisement
albusmw

DescriptionAttribute

Nov 8th, 2020
2,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.29 KB | None | 0 0
  1.     '''<summary>Get a list of all available property names.</summary>
  2.     Private Function GetAllPropertyNames(ByRef TypeToReflect As Type) As List(Of String)
  3.         Dim RetVal As New List(Of String)
  4.         Dim DescriptionAttribute As Type = GetType(System.ComponentModel.DescriptionAttribute)
  5.         For Each SingleProperty As Reflection.PropertyInfo In TypeToReflect.GetProperties()
  6.             Dim PropertyName As String = SingleProperty.Name
  7.             Dim Description As String = GetDescriptionAttribute(CType(SingleProperty, Object))
  8.             If String.IsNullOrEmpty(Description) = False Then PropertyName &= " (" & Description & ")"
  9.             RetVal.Add(PropertyName)
  10.         Next SingleProperty
  11.         Return RetVal
  12.     End Function
  13.  
  14.     Public Shared Function GetDescriptionAttribute(ByRef Element As Object) As String
  15.         Try
  16.             Dim attributes As System.ComponentModel.DescriptionAttribute() = CType(Element.GetType.GetField(Element.ToString).GetCustomAttributes(GetType(System.ComponentModel.DescriptionAttribute), False), System.ComponentModel.DescriptionAttribute())
  17.             If attributes.Length > 0 Then Return attributes(0).Description Else Return String.Empty
  18.         Catch ex As Exception
  19.             Return String.Empty
  20.         End Try
  21.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement