How to get property.value from reflection.assembly?
Dim assembly As Assembly = assembly.GetExecutingAssembly()
For Each assemblyType As Type In assembly.GetTypes()
If assemblyType.IsSubclassOf(GetType(Form)) Then
'Dim name As AssemblyName() = assembly.GetReferencedAssemblies()
If assemblyType.BaseType.ToString.EndsWith("Form2") Then
Dim props As PropertyInfo = _
GetType(Form2).GetProperty("FriendlyName")
If Not props Is Nothing Then
ComboBox1.Items.Add(assemblyType.Namespace )
End If
'//Here I want to get Prop.value that is string type
End If
Building on what Itowlson wrote:
From MCTS: .net 2.0: Application Development Foundation
First get the assembly:
Once you have the type, you can ask it for a ConstructorInfo object to use to construct your new type:
The method represented in a ConstructorInfo object is a specialized MethodBase object that looks and acts like a typical method but always returns an instance of a specific type. In this example, you are asking the Type class to return an empty constructor. (You are supplying an empty Array of Types to specify the empty constructor.) You could also ask for a constructor with specific arguments by supplying an array of the constructor argument types, like so:
Once you have the ConstructorInfo object, creating an object is as simple as invoking the constructor. Here is how to invoke the empty constructor:
Once you have an instance of an object, you simply use reflection to get the info class you need to call, and then you invoke the info class to execute the code.
For example, call the Add method on your new Hashtable instance:
You can now use the PropertyInfo class to get the count of the items in your Hashtable to verify that the Add worked as you expected it to:
To get the value of a property via reflection, call PropertyInfo.GetValue.
However, assuming that this is an instance property, you will need an instance of the type for which the get the property value. For example, if FriendlyName is an instance property of the Form2 class, you will need to specify which instance of Form2 you want to get the FriendlyName for. (And you'll pass this as the obj argument to PropertyInfo.GetValue; you can pass null for the index argument in this case.)