Mega Code Archive

 
Categories / VB.Net / Reflection
 

Invokes specified member, using binding constraints and matching the specified argument list

Imports System Imports System.Reflection Class MyType     Private myField As Int32     Public Sub New(ByRef x As Int32)         x *= 2     End Sub 'New     Public Overrides Function ToString() As [String]         Return myField.ToString()     End Function 'ToString     Public Property MyProp() As Int32         Get             Return myField         End Get         Set(ByVal Value As Int32)             If Value < 1 Then                 Throw New ArgumentOutOfRangeException("value", Value, "value must be > 0")             End If             myField = Value         End Set     End Property End Class 'MyType Class MyApp     Shared Sub Main()         Dim t As Type = GetType(MyType)         Dim args() As [Object] = {8}         Console.WriteLine(args(0))         Dim obj As [Object] = t.InvokeMember(Nothing, BindingFlags.DeclaredOnly Or BindingFlags.Public Or BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.CreateInstance, Nothing, Nothing, args)         Console.WriteLine(obj.GetType().ToString())         Console.WriteLine(args(0))     End Sub  End Class