ROSTAM2
چهارشنبه 13 مهر 1401, 20:18 عصر
با این کد نام تمامی خصوصیات یک کلاس طبق تعیین نوع آن فقط خواندنی(ReadOnly) - فقط نوشتنی(WriteOnly) و همه خصوصیات نماش داده می شه:
154047
بعد از دستور Properties برای نمایش همه all برای نمایش خصوصیات فقط خواندنی ReadOnly و برای خصوصیات فقط نوشتنی WriteOnly تایپ کنید و Enter.
Imports System.Reflection
Module KeyStoreModule
Sub Main()
Dim Words() As String = {""}, Params() As String = {""}
Do Until Words(0).ToLower = "quit"
Console.Write("System.Reflection>")
Words = Console.ReadLine.Split(Space(1))
Select Case Words(0).ToLower
Case "properties"
Console.WriteLine()
If Words.Length = 1 Then
Properties: For Each P As String In PropertyNames()
Console.WriteLine("{0}{1}", vbTab, P)
Next
ElseIf Words.Length = 2 Then
Select Case Words(1).ToLower
Case "all" : GoTo properties
Case "readonly"
For Each P As String In PropertyNames(XMLManager(Of Global.LINQ_To_XML.UserProfileItem).IncludePropert iesOptions.ReadOnly)
Console.WriteLine("{0}{1}", vbTab, P)
Next
Case "writeonly"
For Each P As String In PropertyNames(XMLManager(Of Global.LINQ_To_XML.UserProfileItem).IncludePropert iesOptions.WriteOnly)
Console.WriteLine("{0}{1}", vbTab, P)
Next
End Select
End If
Console.WriteLine()
End Select
Loop
End Sub
Dim PInfo() As PropertyInfo
Public Enum IncludePropertiesOptions
All = 0
ReadAndWrite = 1
[ReadOnly] = 2
[WriteOnly] = 3
End Enum
Function PropertyNames(Optional IncludeOption As IncludePropertiesOptions = IncludePropertiesOptions.All) As IEnumerable(Of String)
Dim Expr As New List(Of String)
Dim Index() As Object = {}
PInfo = GetType(Console).GetProperties()
For Each P As PropertyInfo In PInfo
Select Case IncludeOption
Case IncludePropertiesOptions.All
Expr.Add(P.Name)
Case IncludePropertiesOptions.ReadAndWrite
If P.CanRead = True And P.CanWrite = True Then
Expr.Add(P.Name)
End If
Case IncludePropertiesOptions.ReadOnly
If P.CanRead = True AndAlso P.CanWrite = False Then
Expr.Add(P.Name)
End If
Case IncludePropertiesOptions.WriteOnly
If P.CanRead = False AndAlso P.CanWrite = True Then
Expr.Add(P.Name)
End If
End Select
ContinueFor:
Next
Return Expr.ToArray
End Function
End Module
154047
بعد از دستور Properties برای نمایش همه all برای نمایش خصوصیات فقط خواندنی ReadOnly و برای خصوصیات فقط نوشتنی WriteOnly تایپ کنید و Enter.
Imports System.Reflection
Module KeyStoreModule
Sub Main()
Dim Words() As String = {""}, Params() As String = {""}
Do Until Words(0).ToLower = "quit"
Console.Write("System.Reflection>")
Words = Console.ReadLine.Split(Space(1))
Select Case Words(0).ToLower
Case "properties"
Console.WriteLine()
If Words.Length = 1 Then
Properties: For Each P As String In PropertyNames()
Console.WriteLine("{0}{1}", vbTab, P)
Next
ElseIf Words.Length = 2 Then
Select Case Words(1).ToLower
Case "all" : GoTo properties
Case "readonly"
For Each P As String In PropertyNames(XMLManager(Of Global.LINQ_To_XML.UserProfileItem).IncludePropert iesOptions.ReadOnly)
Console.WriteLine("{0}{1}", vbTab, P)
Next
Case "writeonly"
For Each P As String In PropertyNames(XMLManager(Of Global.LINQ_To_XML.UserProfileItem).IncludePropert iesOptions.WriteOnly)
Console.WriteLine("{0}{1}", vbTab, P)
Next
End Select
End If
Console.WriteLine()
End Select
Loop
End Sub
Dim PInfo() As PropertyInfo
Public Enum IncludePropertiesOptions
All = 0
ReadAndWrite = 1
[ReadOnly] = 2
[WriteOnly] = 3
End Enum
Function PropertyNames(Optional IncludeOption As IncludePropertiesOptions = IncludePropertiesOptions.All) As IEnumerable(Of String)
Dim Expr As New List(Of String)
Dim Index() As Object = {}
PInfo = GetType(Console).GetProperties()
For Each P As PropertyInfo In PInfo
Select Case IncludeOption
Case IncludePropertiesOptions.All
Expr.Add(P.Name)
Case IncludePropertiesOptions.ReadAndWrite
If P.CanRead = True And P.CanWrite = True Then
Expr.Add(P.Name)
End If
Case IncludePropertiesOptions.ReadOnly
If P.CanRead = True AndAlso P.CanWrite = False Then
Expr.Add(P.Name)
End If
Case IncludePropertiesOptions.WriteOnly
If P.CanRead = False AndAlso P.CanWrite = True Then
Expr.Add(P.Name)
End If
End Select
ContinueFor:
Next
Return Expr.ToArray
End Function
End Module