Jeg har fundet ud af det.
Kode:
Imports System.Reflection
Public Enum Attrbutes
None = 0
[Private] = 1
FamANDAssem = 2
[Assembly] = 3
Family = 4
FamORAssem = 5
[Public] = 6
[Static] = 16
End Enum
Public NotInheritable Class PropertyAttributes
Public Shared Function GetPropertyAttributes(ByVal [property] As PropertyInfo) As PropertyAttributes
Dim accssors() As MethodInfo = [property].GetAccessors(True)
Select Case accssors.Length
Case 1
Dim res As New PropertyAttributes
res.isassembly_ = accssors(0).IsAssembly
res.isfamily_ = accssors(0).IsFamily
res.isprivate_ = accssors(0).IsPrivate
res.ispublic_ = accssors(0).IsPublic
res.isstatic_ = accssors(0).IsStatic
res.isfamilyandassembly_ = accssors(0).IsFamilyAndAssembly
res.isfamilyorassembly_ = accssors(0).IsFamilyOrAssembly
If res.isprivate_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Private
End If
If res.ispublic_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Public
End If
If res.isstatic_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Static
End If
If res.isfamilyandassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.FamANDAssem
ElseIf res.isfamilyorassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.FamORAssem
End If
If res.isfamily_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Family
End If
If res.isassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Assembly
End If
Return res
Case 2
Dim method As MethodInfo = Nothing
If accssors(0).IsPrivate Then
If accssors(1).IsFamily Or accssors(1).IsFamilyAndAssembly Or accssors(1).IsFamilyOrAssembly Or accssors(1).IsAssembly Or accssors(1).IsPublic Then
method = accssors(1)
Else
method = accssors(0)
End If
ElseIf accssors(0).IsFamily Then
If accssors(1).IsFamilyAndAssembly Or accssors(1).IsFamilyOrAssembly Or accssors(1).IsAssembly Or accssors(1).IsPublic Then
method = accssors(1)
Else
method = accssors(0)
End If
ElseIf accssors(0).IsFamilyAndAssembly Or accssors(0).IsFamilyOrAssembly Then
If accssors(1).IsAssembly Or accssors(1).IsPublic Then
method = accssors(1)
Else
method = accssors(0)
End If
ElseIf accssors(0).IsAssembly Or accssors(0).IsPublic Then
If accssors(1).IsPublic Then
method = accssors(1)
Else
method = accssors(0)
End If
End If
Dim res As New PropertyAttributes
res.isassembly_ = method.IsAssembly
res.isfamily_ = method.IsFamily
res.isprivate_ = method.IsPrivate
res.ispublic_ = method.IsPublic
res.isstatic_ = method.IsStatic
res.isfamilyandassembly_ = method.IsFamilyAndAssembly
res.isfamilyorassembly_ = method.IsFamilyOrAssembly
If res.isprivate_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Private
End If
If res.ispublic_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Public
End If
If res.isstatic_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Static
End If
If res.isfamilyandassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.FamANDAssem
ElseIf res.isfamilyorassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.FamORAssem
End If
If res.isfamily_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Family
End If
If res.isassembly_ Then
res.attributes_ = res.attributes_ Or Attrbutes.Assembly
End If
Return res
End Select
Return Nothing
End Function
Private attributes_ As Attrbutes
Public ReadOnly Property Attributes As Attrbutes
Get
Return attributes_
End Get
End Property
Private ispublic_ As Boolean
Public ReadOnly Property IsPublic As Boolean
Get
Return ispublic_
End Get
End Property
Private isprivate_ As Boolean
Public ReadOnly Property IsPrivate As Boolean
Get
Return isprivate_
End Get
End Property
Private isassembly_ As Boolean
Public ReadOnly Property IsAssembly As Boolean
Get
Return isassembly_
End Get
End Property
Private isfamily_ As Boolean
Public ReadOnly Property IsFamily As Boolean
Get
Return isfamily_
End Get
End Property
Private isstatic_ As Boolean
Public ReadOnly Property IsStatic As Boolean
Get
Return isstatic_
End Get
End Property
Private isfamilyandassembly_ As Boolean
Public ReadOnly Property IsFamilyAndAssembly As Boolean
Get
Return isfamilyandassembly_
End Get
End Property
Private isfamilyorassembly_ As Boolean
Public ReadOnly Property IsFamilyOrAssembly As Boolean
Get
Return isfamilyorassembly_
End Get
End Property
End Class
Public Class Form1
Protected Shared Property abc As String
Private Get
End Get
Set(value As String)
End Set
End Property
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim attributes As PropertyAttributes = PropertyAttributes.GetPropertyAttributes(GetType(Form1).GetProperty("abc", BindingFlags.NonPublic Or BindingFlags.Static))
End Sub
End Class
arne_v skriv et svar så får du point.