Solved

c# reflection - GetFields not returning values

Posted on 2011-09-12
3
566 Views
Last Modified: 2013-12-17
Hi,

the following piece of code is returning no fieldInfo values:

Type type = ev.GetType();
                FieldInfo[] fields = type.GetFields();

Open in new window


where type is an instance of the following object:

 public class Event : iEvent
    {
        #region iEvent Members

        private string identifierName;

        public string IdentifierName
        {
            get { return identifierName; }
            set { identifierName = value; }
        }
        private int subclassId;

        public int SubclassId
        {
            get { return subclassId; }
            set { subclassId = value; }
        } 

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private DateTime startTime;

        public DateTime StartTime
        {
            get { return startTime; }
            set { startTime = value; }
        }
}

Open in new window


can somebody tell me how to make the fields readable?

Thanks
0
Comment
Question by:basil365
[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
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 36523103
Try this:
FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);

Open in new window

0
 
LVL 13

Expert Comment

by:Naman Goel
ID: 36523226
your field are not public, so add following BindingFlags to get those values:

FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
Type type = new Event().GetType();
            MemberInfo[] members = type.GetMembers();
            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);

            List<PropertyInfo> lstPropertyInfo = new List<PropertyInfo>();

            foreach (var item in members)
            {
                switch (item.MemberType)
                {
                    case MemberTypes.All:
                        break;
                    case MemberTypes.Constructor:
                        break;
                    case MemberTypes.Custom:
                        break;
                    case MemberTypes.Event:
                        break;
                    case MemberTypes.Field:
                        break;
                    case MemberTypes.Method:
                        break;
                    case MemberTypes.NestedType:
                        break;
                    case MemberTypes.Property:
                        lstPropertyInfo.Add(item as PropertyInfo);
                        break;
                    case MemberTypes.TypeInfo:
                        break;
                    default:
                        break;
                }
            }

Open in new window

0
 

Author Comment

by:basil365
ID: 36523501
apologies - i had already closed it before the 2nd reply
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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