Public Function xxx (Byval c As String) As String
Return c + "Hello World"
End Function
Public Shared Function xxx (Byval c As String) As String
Return c + "Hello World"
End Function
เอาตัวเต็มไปเลยครับ MADE BY หน้าฮี Code (VB.NET)
Imports System.Reflection
Public Class ReflectionMgr
Private Shared flags As BindingFlags = BindingFlags.Public Or Reflection.BindingFlags.NonPublic Or BindingFlags.Static Or
BindingFlags.Instance Or BindingFlags.DeclaredOnly
Sub New()
End Sub
''' <summary>
''' runtime load assembly
''' </summary>
''' <param name="fullname">"yourPath/yourDLL.dll"</param>
''' <returns></returns>
''' <remarks>Web Application System.Web.HttpContext.Current.Server.MapPath(fullname)</remarks>
Public Shared Function LoadAssembly(ByVal fullname As String) As System.Reflection.Assembly
Try
Return Assembly.LoadFrom(fullname)
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' runtime get Type
''' </summary>
''' <param name="ass">Assembly object example LoadAssembly(ByVal fullname As String) As System.Reflection.Assembly</param>
''' <param name="fullname">string class name example "ERP_Model.usrBSCUnit"</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function LoadType(ByVal ass As Assembly, fullname As String) As System.Type
Try
Return ass.CreateInstance(fullname).GetType()
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' return Private property only
''' </summary>
''' <param name="t">LoadType(ByVal ass As Assembly, fullname As String) As System.Type</param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetFieldInfo(ByVal t As System.Type) As FieldInfo()
Try
Return t.GetFields(flags)
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' return Inherits Property
''' </summary>
''' <param name="t"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetBaseTypeFieldInfo(ByVal t As System.Type) As FieldInfo()
Try
Return t.BaseType().GetFields(flags)
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' Get All field Inherits/Private Property
''' </summary>
''' <param name="t"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Shared Function GetAllFieldInfo(ByVal t As System.Type) As IEnumerable(Of FieldInfo)
'2010-11-18 Fixed Bug
'Public Shared Function GetAllFieldInfo(ByVal t As System.Type) As FieldInfo() to As Object
'Error Unable to cast object of type
'<UnionIterator>d_88'1[System.Reflection.FieldInfo]' to type
'System.Reflection.Fieldinfo'.
Try
Return t.GetFields(flags).Union(t.BaseType().GetFields(flags))
Catch ex As Exception
Return Nothing
End Try
End Function
Public Shared Function GetMethodInfo(ByVal t As System.Type, ByVal MethodName As String) As System.Reflection.MethodInfo
Try
Return t.GetMethod(MethodName, New Type() {}) 'Fix bug ambiguous overload function/method
Catch ex As Exception
Return Nothing
End Try
End Function
Public Shared Function GetMethodInfo(ByVal t As System.Type, ByVal MethodName As String, ByVal paraArray() As System.Type) As System.Reflection.MethodInfo
Try
Return t.GetMethod(MethodName, paraArray)
Catch ex As Exception
Return Nothing
End Try
End Function
Public Shared Function GetMethodsInfo(ByVal t As System.Type, ByVal MethodName As String) As System.Reflection.MethodInfo()
Try
Return t.GetMethods()
Catch ex As Exception
Return Nothing
End Try
End Function
Public Shared Function InvokeMethod(ByVal m As MethodInfo) As Object
Try
Return m.Invoke(New Object() {}, New Object() {})
Catch ex As Exception
Return Nothing
End Try
End Function
''' <summary>
''' InvokeMethod in assembly
''' </summary>
''' <param name="m">GetMethodInfo(ByVal t As System.Type, ByVal MethodName As String) As System.Reflection.MethodInfo</param>
''' <param name="args">Dim args As Object() = New Object() {1, "car01", Today}</param>
''' <returns>Object</returns>
''' <remarks></remarks>
Public Shared Function InvokeMethod(ByVal m As MethodInfo, ByVal args() As Object) As Object
Try
Return m.Invoke(New Object() {}, args)
Catch ex As Exception
Return Nothing
End Try
End Function
End Class