这真的应该返回一个空的 String() 吗?
我有一个属性类:
<AttributeUsage(AttributeTargets.Property)> _
Public Class DirectoryAttribute
Inherits Attribute
Private _attribute As String
Public Sub New(ByVal attribute As String)
_attribute = attribute
End Sub
Public ReadOnly Property Attribute As String
Get
Return _attribute
End Get
End Property
End Class
以及接口和类:
Public Interface IDirentoryEntity
<DirectoryAttribute("Name")> _
Property Name As String
End Interface
Public Interface IOrganizationalUnit
Inherits IDirectoryEntity
End Interface
Public Class OrganizationalUnit
Implements IOrganizationalUnit
' Implementing IOrganizationalUnit here...'
End Class
Public Interface IIdentifiableDirectoryEntity
Inherits IDirectoryEntity
<DirectoryAttribute("sAMAccountName")> _
Property Login As String
End Interface
Public Interface IGroup
Inherits IIdentifiableDirectoryEntity
End Interface
Public Class Group
Implements IGroup
Private _attributes() As String
' Implementing IGroup here...'
Private ReadOnly Property Attributes() As String()
Get
If (_attributes Is Nothing) Then
Dim attr() As DirectoryAttribute = _
CType(GetType(Group).GetCustomAttributes(GetType(DirectoryAttribute), True), DirectoryAttribute())
If (attr Is Nothing OrElse attr.Length = 0 OrElse attr(0) Is Nothing) Then _
Return New String(0) { }
_attributes = New String(attr.Length) { }
For index As Integer = 0 To attr.Length - 1 Or _attributes.Length - 1 Step 1
_attributes(index) = attr(index).Attribute
Next
End If
Return _attributes
End Get
End Property
End Class
话虽如此,Private Property Attributes() As String()
是否应该返回放置在接口上的 DirectoryAttribute
的值属性也是如此,因为我在 Type.GetCustomAttributes
方法的继承参数中指定了 True ?
I have an attribute class:
<AttributeUsage(AttributeTargets.Property)> _
Public Class DirectoryAttribute
Inherits Attribute
Private _attribute As String
Public Sub New(ByVal attribute As String)
_attribute = attribute
End Sub
Public ReadOnly Property Attribute As String
Get
Return _attribute
End Get
End Property
End Class
And interfaces and classes:
Public Interface IDirentoryEntity
<DirectoryAttribute("Name")> _
Property Name As String
End Interface
Public Interface IOrganizationalUnit
Inherits IDirectoryEntity
End Interface
Public Class OrganizationalUnit
Implements IOrganizationalUnit
' Implementing IOrganizationalUnit here...'
End Class
Public Interface IIdentifiableDirectoryEntity
Inherits IDirectoryEntity
<DirectoryAttribute("sAMAccountName")> _
Property Login As String
End Interface
Public Interface IGroup
Inherits IIdentifiableDirectoryEntity
End Interface
Public Class Group
Implements IGroup
Private _attributes() As String
' Implementing IGroup here...'
Private ReadOnly Property Attributes() As String()
Get
If (_attributes Is Nothing) Then
Dim attr() As DirectoryAttribute = _
CType(GetType(Group).GetCustomAttributes(GetType(DirectoryAttribute), True), DirectoryAttribute())
If (attr Is Nothing OrElse attr.Length = 0 OrElse attr(0) Is Nothing) Then _
Return New String(0) { }
_attributes = New String(attr.Length) { }
For index As Integer = 0 To attr.Length - 1 Or _attributes.Length - 1 Step 1
_attributes(index) = attr(index).Attribute
Next
End If
Return _attributes
End Get
End Property
End Class
With that said, shall the Private Property Attributes() As String()
not return the values of DirectoryAttribute
placed over the interfaces properties as well, since I specify True in the inheritance parameter of the Type.GetCustomAttributes
method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为有两个主要的混淆点:
I think there are two main points of confusion: