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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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