How can i get the Property value using Reflection (Return type: Collection of controls)

dotnet framework

    Next

  • 1. Remote Process
    how to find remote machine Processes Main Window Title ?? through this code i can find local machine Process Main Window Titl . thanku Dim i Dim Prc() As Process Prc = Process.GetProcesses("faraz") '''''''''''''pass localhos For i = 0 To UBound(Prc) If (Prc(i).MainWindowTitle.ToString <> "") Then TreeView1.Nodes.Add(Prc(i).MainWindowTitle.ToString) End If Next
  • 2. Online community/portal site
    Hello, I am starting to plan a portal site that will eventually (hopefully) increase exponetianlly in the amount of traffic to the site. I am planning to do this in a 3-tier/4-tier layout, I'm just wondering of any design considerations before I embark. One thing I was thinking of is originally all tiers will reside on one physical system, eventually the tiers will be seperated. Initially do I want to create web services for each of the tiers? Or would I do that when I am moving the tiers to additional systems. I guess my main concern here is, how do I design the app so I can easily switch a layer from non-webservice to a webservice without too many headaches. Maybe I am thinking too much about the problem, but I am trying to get a full lay of the land before I begin. Any advice would be appreciated. Thank you DKode
  • 3. CD/DVD Media SerialNumber
    Hi, I am writing myself a "keep organised" app to keep track of all the stuff on my backup DVDs/CDs. I wanted to be able to recognise the dvd/CD when its in the drive, and I figured that the manufacturer burnt serial number on each CD/DVD disc would be a good, unique, non-changing identifier. But I can't work out how to get at it via the Win32_PhysicalMedia and Win32_CDROMDrive classes. How do I match the results from the test code below to the Win32_CDROMDrive classes? ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"); foreach (ManagementObject wmi_CD in searcher.Get()) { if (wmi_CD["SerialNumber"] == null) Console.WriteLine("None"); else Console.WriteLine(wmi_CD["SerialNumber"].ToString()); } If I run this code I get two results returned for instance, one great long number, (presumably the SerialNumber of the CD media in the drive), and one result of "None", (presumably from the empty floppy drive), but I can't see how to match the serialnumber to a drive. I have read through the docs on MSDN, but I can't see the common property that I can take from the Win32_CDROMDrive to the Win32_PhysicalMedia class to make sure I have the correct drive. (I am probably just being dumb....) (Hope this is clear, and if I have explained it badly let me know and I will answer with a better explanation.) Thanks for any help. regards, Gary

How can i get the Property value using Reflection (Return type: Collection of controls)

Postby Mudassar » Sat, 09 Apr 2005 02:03:34 GMT

i want to get the property value using reflection.

Scenerio:
  i have a status bar on MDI form. it has property named "Panels" and i want 
to get a specific panel from that
panels collection using reflection.
    Please let me know.

Thanks
C# Developer
Mudassar 



Re: How can i get the Property value using Reflection (Return type: Collection of controls)

Postby Pete Davis » Sat, 09 Apr 2005 03:07:48 GMT

Funny you should ask today. There's been a lot of reflection going on in our
office today. Here's a sample of getting a field:

string dataField;
FieldInfo fi = currentManager.GetType().GetField("dataField",
BindingFlags.NonPublic | BindingFlags.Instance);
dataField = (string) fi.GetValue(currentManager);


Basically, you'll want to get ProeprtyInfo instead of a FieldInfo (using
GetProperty()), but otherwise it's more or less the same.

In this case, currentManager is a "CurrencyManager" object and "dataField"
is a private field in the CurrencyManager.

The key is to make sure your BindingFlags values are correct. These should
work for non-public instance fields. If it's static or public (I doubt it's
public, otherwise why use reflection, right?), make the appropriate changes.

Hope that helps.

Pete






want



Re: How can i get the Property value using Reflection (Return type: Collection of controls)

Postby Mudassar Khan » Wed, 13 Apr 2005 00:35:45 GMT

Pete Davis,
    Thanks for the reply and sample code.
i solved my requirement in the following way 


object MainForm = this.GetMainForm();
object statusBar =
MainForm.GetType().InvokeMember("StatusBar",BindingFlags.GetProperty,nul
l,MainForm,null);

IList panels = (IList)statusBar.GetType().GetProperty
("Panels").GetGetMethod().Invoke(statusBar,null);
object progressPanel = panels[1];

progressPanel.GetType().GetProperty("Visible").SetValue(progressPanel,tr
ue,null);

this is how i get the List and get a specific object from list and set
its property.

Regards
Mudassar

*** Sent via Developersdex  http://www.**--****.com/  ***

Similar Threads:

1.Getting list of Properties using Reflection

Hi,

I'm trying to get a list of properties from a hierarchy of classes, 
using reflection.

Using Type.GetProperties(), I get the list back in "reverse hierarchy 
order" (derived class properties before parent class properties)

Using TypeDescriptor.GetProperties(), the order of the returned 
properties is also wrong.

I used the XmlSerializer to test my classes, and the properties was 
written out correctly (Parent class before derived class).

What can I do to get a list of properties in the correct order (Parent 
class before inherited class)?

Thanks for the help,
Dawid Mostert
 XXXX@XXXXX.COM 

2.Assign Property value using Reflection

assuming that I have a class

public class MyClass {
    public string FirstName {
        get {...}
        set {...}
    }
}

how can I assign the FirstName property using reflection on a generic class 
of type MyClass?

string propertyName = "FirstName";
C is a gerneric type of type "MyClass"

so what I want to do is:
C.propertyName  = "Andrew"; // <-pseudo code...

For the simplicity, lets assume that the property is always of type string 
but it could very (an I will know the type ahead of time.)

Thanks,



-- 

Andrew Robinson


3.Using Enumerated Values to Access Property Collection

Hi,

I have an enum type as defined below. The enum constants are some of
the properties for a windows form control. I want to store the
settings for that control into a file. In order to access the value of
the properties (for example toolbar.Size or Toolbar.Name) I used a for
loop. In my for loop, I want to do something like
toolbar.[Enum](Prop.GetName)(which is equal to toolbar.Size and
returns the value into the string)

        Public Enum ToolBarSettings
            Name
            Size
            Location
        End Enum

      Dim Properties As Type = GetType(ToolBarSettings)
           For Each Prop In [Enum].GetNames(Properties)
               Dim s as string = toolbar.[Enum](Prop.GetName) ' I want
this to return toolbar.size into the string)
           Next

Is there a way that I can do this?

Thank you
Gos

4.server control collection with several types of properties

Is it possible to implement a server control that will look like this:
<just:control>
  <columns>
    <columnTypeA id=1></columnTypeA>
    <columnTypeA id=2></columnTypeA>
    <columnTypeB id=3></columnTypeB>
    <columnTypeB id=4></columnTypeB>
  </columns>
</just:control>

While columnTypeA is a collection and columnTypeB is a different collection? 
Another option is that both tags will be in the same collection (if 
possible..)
Thanks.

5.Setting the value of a Master page's control's property using a property of the Master page

6. Error getting Identity Value using Strongly Typed dataset

7. Using Reflection to get a Field Value from Control

8. Getting ID, calling url, search for value, return value



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 11 guest