Solved

How to check if a property exists on an object and get the value of that property using reflection?

Posted on 2010-09-22
2
464 Views
Last Modified: 2013-11-07
hi,

I need to check if a property exists on an object and get the value of that property if the property exists.
I have the attached code.
Thanks for any suggestions.



PropertyInfo info;

		            foreach (Field FO in section.FOCollection)
                    {
                        info = Myobj.GetType().GetProperty(FO.Node);
                        
                    }


if(info!=null)
{
 //get the value
}

Open in new window

0
Comment
Question by:ipjyo
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33739028
Like this....

    System.Reflection.PropertyInfo info = Myobj.GetType().GetProperty(FO.Node);
    if (info != null) {
        string value = info.GetValue(Myobj, null);
    }

Wayne
0
 

Author Comment

by:ipjyo
ID: 33743815
Thank you.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now