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
469 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now