|
|
|
Click here to copy the following block |
Imports System.Reflection
Module MainModule
Sub Main() Dim args() As String = Environment.GetCommandLineArgs() Dim cmd As String = Environment.CommandLine Dim ty As Type Dim mbrTypes As MemberTypes = MemberTypes.All Dim mbrName As String = "" Dim mi As MemberInfo
If args.Length <= 1 OrElse args(1) = "/?" OrElse String.Compare(args(1), _ "/help", True) = 0 Then Console.WriteLine("Command-line Type Browser - by Francesco Balena") Console.WriteLine(" Syntax: typebrow typename [membername[*]]") Exit Sub End If
Dim i As Integer = args(1).IndexOf(","c) If i < 0 Then ty = Type.GetType(args(1), False, True) Else Dim asmname As String = args(1).Substring(i + 1) Dim asm As [Assembly] = [Assembly].LoadWithPartialName(asmname) ty = asm.GetType(args(1).Substring(0, i), False, True) End If
If ty Is Nothing Then Console.WriteLine("Unable to create type ""{0}""", args(1)) Exit Sub End If
If args.Length > 2 Then mbrName = args(2) End If
Dim minfos() As MemberInfo = ty.FindMembers(mbrTypes, _ BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.Static, _ AddressOf CustomMemberFilter, mbrName)
For Each mi In minfos Console.WriteLine(MemberDescription(mi)) Next End Sub
Function CustomMemberFilter(ByVal m As MemberInfo, _ ByVal filterCriteria As Object) As Boolean If m.Name.StartsWith("get_") Or m.Name.StartsWith("set_") Then Return False End If
Dim search As String = filterCriteria.ToString.ToUpper If search = "" Then Return True
If search.EndsWith("*") Then If m.Name.ToUpper.StartsWith(search.Substring(0, _ search.Length - 1)) Then Return True Else If m.Name.ToUpper = search Then Return True End If End Function
Function MemberDescription(ByVal mi As MemberInfo) As String Dim res As String
Select Case mi.MemberType Case MemberTypes.Field Dim fdi As FieldInfo = CType(mi, FieldInfo) res &= NameDescription(mi, fdi.IsStatic) & VBTypeDescription _ (fdi.FieldType)
Case MemberTypes.Property Dim pri As PropertyInfo = CType(mi, PropertyInfo) res &= NameDescription(mi, False) & ParamListDescription _ (pri.GetIndexParameters) res &= VBTypeDescription(pri.PropertyType)
Case MemberTypes.Method Dim mti As MethodInfo = CType(mi, MethodInfo) res &= NameDescription(mi, mti.IsStatic) & ParamListDescription _ (mti.GetParameters) If Not (mti.ReturnType Is Nothing) Then res &= VBTypeDescription(mti.ReturnType, True) End If
Case MemberTypes.Constructor Dim cti As ConstructorInfo = CType(mi, ConstructorInfo) res &= NameDescription(mi, False) & ParamListDescription _ (cti.GetParameters)
Case MemberTypes.Event Dim evi As EventInfo = CType(mi, EventInfo) Dim delType As Type = evi.EventHandlerType Dim mi2 As MethodInfo = delType.GetMethod("Invoke") res &= NameDescription(mi, False) & ParamListDescription _ (mi2.GetParameters) End Select
Return res End Function
Function NameDescription(ByVal mi As MemberInfo, ByVal IsStatic As Boolean) _ As String Dim res As String
If IsStatic Then res = "Shared " End If
If mi.MemberType <> MemberTypes.Method Then res &= [Enum].Format(mi.MemberType.GetType, mi.MemberType, _ "G") & " " Else Dim meth As MethodInfo = CType(mi, MethodInfo) If meth.ReturnType.Name = "Void" Then res &= "Sub " Else res &= "Function " End If End If
If mi.MemberType = MemberTypes.Constructor Then res &= "New" Else res &= mi.Name End If
Return res End Function
Function ParamListDescription(ByVal pinfos() As ParameterInfo) As String Dim res As String = "(" Dim i As Integer
For i = 0 To pinfos.GetUpperBound(0) res &= ParamDescription(pinfos(i)) If i < pinfos.GetUpperBound(0) Then res &= ", " Next Return res & ")" End Function
Function ParamDescription(ByVal pi As ParameterInfo) As String Dim res As String Dim pt As Type = pi.ParameterType
If pi.IsOptional Then res = "Optional "
If pt.IsByRef Then res &= "ByRef " Else res &= "ByVal " End If
res &= pi.Name res &= VBTypeDescription(pt)
If pi.IsOptional Then If pt Is GetType(System.String) Then res &= " = """ & pi.DefaultValue.ToString & """" Else res &= " = " & pi.DefaultValue.ToString End If End If
Return res End Function
Function VBTypeDescription(ByVal ty As Type, _ Optional ByVal PostfixArrayMarks As Boolean = False) As String Dim res As String
res &= ty.Name If res.EndsWith("[]") Then res = res.Substring(0, res.Length - 2) End If If res.EndsWith("*") Then res = res.Substring(0, res.Length - 1) End If
Select Case res Case "Int16" res = "Short" Case "Int32" res = "Integer" Case "Int64" res = "Long" Case "Void" Return "" End Select
If Not ty.IsArray Then res = " As " & res ElseIf PostfixArrayMarks Then res = " As " & res & "()" Else res = "() As " & res End If
Return res End Function
End Module |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|