469,289 Members | 2,063 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,289 developers. It's quick & easy.

C#-APP: Type.GetProperty and GetProperties not working.

I'm having trouble getting the Type.GetProperty(string) method to return the property that I need. Whenever I call it all I get is a null value even thought the type that i'm calling does contain the property. By adding a watch I also noticed that the Type.GetProperties() method is always returning an empty array. Am I using the method incorrectly or am I using the wrong method?

Expand|Select|Wrap|Line Numbers
  1. if (type.Namespace == "ATE.Config")
  2. {
  3.      PropertyInfo t = type.GetProperty("configType",BindingFlags.Static);
  4.      if (t != null)
  5.      {
  6.           t.SetValue(null, type.Name, null);
  7.      }
  8. }
Nov 13 '08 #1
3 9911
7,872 Expert 4TB
My guess is you are not using the correct combination of bindingflags to get the properties to return
Nov 13 '08 #2
I'd tried all bindings possibilities to check for that and it never worked. I did see the GetField method. That worked as expected. After doing some googling i discovered that I didn't know what a property is in a C# (I'd assumed it was the C# term for a field). Thanks for your help though.
Nov 13 '08 #3
7,872 Expert 4TB
Ahh, no. A Property in C# has the form of say
Expand|Select|Wrap|Line Numbers
  1. private int _myint=0;
  2. public int MyIntProperty
  3. {
  4.    get
  5.    {
  6.       return _myint;
  7.    }
  8.    set
  9.    {
  10.       _myint=value;
  11.    }
  12. }
Nov 13 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Robert Zurer | last post: by
15 posts views Thread by satankidneypie | last post: by
2 posts views Thread by crabel | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.