Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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