Paramater Value of a Constructor - Windows Form

Anil Issac

Member
Joined
Apr 28, 2007
Messages
5
Programming Experience
3-5
I am working on a plugin based application and I have a navigation architecture in my base module. I am storing the form information in cache (like a view state). Now I will explain my question with an example below;
VB.NET:
'Instance of a form (in plugin module) with a Param, ;Passing ParamValue=10
Dim obj As Object = New Form2(10)
 
'Now I want to retain the value of parameter from the object 'obj
Dim t As Type = obj.GetType()
Dim ctrInfo As ConstructorInfo()
ctrInfo = t.GetConstructors()
For Each c As ConstructorInfo In ctrInfo
'Here I am getting total number of Params passed
MsgBox(c.GetParameters().Length)
Dim pif As ParameterInfo() = c.GetParameters()
'Here I am getting the type of parameter
For Each p As ParameterInfo In pif
MsgBox(p.Position & " Type: " & p.ParameterType.ToString & " parameter name: " & p.Name)
'Now my question is how I will get the value assigned to that parameter ie ParamValue =10
Next
Next
Can you please suggest a solution how I can retrive the parameter value of the object?
 
Last edited by a moderator:
You are inspection a type, not an instance. You can't get that value.
 
As per my requirement above, My base module will not get information such as Form name, Parameters and their values. Only the instantiated objects of each of the form classes in the plug-in module.
So no other solution to get the value?
 
You can store it in a private field like this:
VB.NET:
Class test
    Private ii As Integer
    Public Sub New(ByVal i As Integer)
        ii = i
    End Sub
End Class
and get the value:
VB.NET:
Dim tObject As New test(60)
MsgBox(tObject.GetType.GetField("ii", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(tObject).ToString())
Form name? Do you mean this:
VB.NET:
MsgBox(DirectCast(obj, Form).Name)
 
typically when we want to know smething about an instance, we just ask the instance.
In a plugin app, you would make an instance of your plugin, and then ask if for whatever value you were interested in.. why are you reflecting?
 
Back
Top