我新的自定義屬性,所以我不知道是否有可能獲得屬性的值。在我的課,我使用自定義屬性,屬性的一個例子是:VB.net屬性值
Private mFiller As String
<Position(378), Length(34), DataType("A"), ParticipantDependant("P/D"), RequiredProperty("Required"), Format("Blank")> _
Public Property Filler() As String
Get
Return mFiller
End Get
Set(ByVal value As String)
mFiller = value
End Set
End Property
我試圖讓這些屬性的值(即獲取位置= 378,長度= 34等。) 。迴路我和看起來像這樣開頭:
Dim gwlImport As New ClientGWLImport
Dim properties() As PropertyInfo = gwlImport.GetType.GetProperties
Dim tmpInfo As PropertyInfo
For Each tmpInfo In properties
Debug.Print("Attributes for : " & tmpInfo.Name)
For Each tmpAttribute As Object In tmpInfo.GetCustomAttributes(True)
Debug.Print(tmpAttribute.ToString)
Next tmpAttribute
Next tmpInfo
這讓我的所有屬性的名字,但我不知道如何得到的值。有任何想法嗎?
乾杯,
瑞安
posAtt = tmpInfo.GetCustomAttributes(的GetType(PositionAttribute),真)(0)作爲PositionAttribute ????新的語法? – Codezy 2009-12-21 18:25:28
除了語法錯誤之外,它正是我正在尋找的。它應該閱讀: posAtt = CTYPE(tmpInfo.GetCustomAttributes(的GetType(PositionAttribute),真)(0),PositionAttribute) – bornbnid 2009-12-21 18:28:03
很抱歉的語法錯誤;我太習慣C#了。 – SLaks 2009-12-21 19:24:56