Click here to Skip to main content
15,914,820 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi
i've created multiple forms in my project. i have to store the form names to the databse. I can get the types like this

SampleAssembly = [Assembly].LoadFrom(Assembly.GetExecutingAssembly().Location)
       Dim types As Type() = SampleAssembly.GetTypes()


I can get the form name using this types(i).Name. But i could not retrive the other properties like form Text,Enabled,BackColor etc..
This is my code strVal=types(i).GetProperty("Text").GetValue(SampleAssembly, Nothing). But its not working. How to get the text


This is my Full Code

Dim SampleAssembly As Assembly
       SampleAssembly = [Assembly].LoadFrom(Assembly.GetExecutingAssembly().Location)
       Dim types As Type() = SampleAssembly.GetTypes()
        DataGridView1.Rows.Add()
       DataGridView1.Item(0, 0).Value = "Select All"
        For i As Integer = 0 To types.Length - 1
           If types(i).BaseType.Name = "Form" And types(i).Name.StartsWith("frm") And types(i).Name <> "frmPOSMaster" Then
               DataGridView1.Rows.Add()
               DataGridView1.Item(0, DataGridView1.Rows.Count - 1).Value = types(i).Name
               DataGridView1.Item(2, DataGridView1.Rows.Count - 1).Value = types(i).GetProperty("Text").GetValue(SampleAssembly, Nothing)


           End If
       Next
Posted
Updated 19-Apr-14 12:40pm
v5
Comments
[no name] 19-Apr-14 18:10pm    
http://stackoverflow.com/questions/9758051/get-type-using-reflection
sencsk 19-Apr-14 18:25pm    
I tried this. But not working

strVal=types(i).GetProperty("Text").GetValue(SampleAssembly, Nothing)

1 solution

Ask yourself, what is "Form", type or an instance of the type (object)? When you use types(i).Name, you find the name of the type. The properties like Text, Enabled, etc., are instance properties, their values depends on instance and have different values for different instances.

If you got property info, you can get the value of the static property without having a reference to the instance, but for an instance (non-static) property, you need an instance. Here is how you can get the value:
http://msdn.microsoft.com/en-US/library/windowsphone/develop/hh194385%28v=vs.105%29.aspx[^].

The parameter of this call is the reference to an instance. For a static property, it should be null.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900