I can't reflect a custom class. 
Author Message
 I can't reflect a custom class.

(Sorry for cross-posting, it's important)

I have a class called User (which is self-explanitory) but when I try to do
something like...
PropertyInfo[] properties = new User().GetType().GetProperties();
int propCount = properties.Length;
...for some reason propCount comes back 0, which means no properties were
found.
If I do the same thing above with a class from the .NET framework or from
the same assembly it works fine.
Can someone please help me? I'm trying to do DataMapping but I can't if this
part won't work.

Cheers,
John



Wed, 12 Jan 2005 09:24:40 GMT  
 I can't reflect a custom class.
Don't mind me asking... but do you have any properties (with
getter/setters)?
Are they public?
Does GetFields() return anything?
Try the GetProperties(BindingFlags.NonPublic | BindingFlags.Public);


Quote:
> (Sorry for cross-posting, it's important)

> I have a class called User (which is self-explanitory) but when I try to
do
> something like...
> PropertyInfo[] properties = new User().GetType().GetProperties();
> int propCount = properties.Length;
> ...for some reason propCount comes back 0, which means no properties were
> found.
> If I do the same thing above with a class from the .NET framework or from
> the same assembly it works fine.
> Can someone please help me? I'm trying to do DataMapping but I can't if
this
> part won't work.

> Cheers,
> John



Wed, 12 Jan 2005 14:48:02 GMT  
 I can't reflect a custom class.
I'm currently working on an example class which is only 4 public strings;
FirstName, LastName, Email, and Username, with an empty constructor. I have
no getters/setters.
I tried your suggestions...
Using the BindingFlags.Public option doesn't help.
GetFields() doesn't return anything.

I made a mistake in my earlier post, none of my class's
GetType().GetProperties() methods return anything (I said that the ones in
the same assembly do, they actually don't).
The weird thing is that the .NET Framework classes all do but none of mine
do. Do I have to override the GetType() method of my custom classes?

Cheers,
John

Quote:

> Don't mind me asking... but do you have any properties (with
> getter/setters)?
> Are they public?
> Does GetFields() return anything?
> Try the GetProperties(BindingFlags.NonPublic | BindingFlags.Public);



> > (Sorry for cross-posting, it's important)

> > I have a class called User (which is self-explanitory) but when I try to
> do
> > something like...
> > PropertyInfo[] properties = new User().GetType().GetProperties();
> > int propCount = properties.Length;
> > ...for some reason propCount comes back 0, which means no properties
were
> > found.
> > If I do the same thing above with a class from the .NET framework or
from
> > the same assembly it works fine.
> > Can someone please help me? I'm trying to do DataMapping but I can't if
> this
> > part won't work.

> > Cheers,
> > John



Wed, 12 Jan 2005 15:52:13 GMT  
 I can't reflect a custom class.
Hi,

Try taking the spaces out between the bindingflags as so:

Quote:
>>GetProperties(BindingFlags.NonPublic|BindingFlags.Public);

HTH

Ben



Thu, 13 Jan 2005 00:37:35 GMT  
 I can't reflect a custom class.
Try this C# console application:

<--- from here

using System;
using System.Reflection;

namespace PropInfos
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 class Student
 {
  private string _name;
  private int _age;

  public string name
  {
   get
   {
    return _name;
   }
   set
   {
    _name = value;
   }
  }

  public int age
  {
   get
   {
    return _age;
   }
   set
   {
    _age = value;
   }
  }

  static void Main(string[] args)
  {
   PropertyInfo[] pi = Type.GetType("PropInfos.Student").GetProperties();

   for (int i = 0; i < pi.Length; i++)
    Console.WriteLine("Property \"" + pi[i].Name + "\"");
  }
 }

Quote:
}

to here ---->


Quote:
> I'm currently working on an example class which is only 4 public strings;
> FirstName, LastName, Email, and Username, with an empty constructor. I
have
> no getters/setters.
> I tried your suggestions...
> Using the BindingFlags.Public option doesn't help.
> GetFields() doesn't return anything.

> I made a mistake in my earlier post, none of my class's
> GetType().GetProperties() methods return anything (I said that the ones in
> the same assembly do, they actually don't).
> The weird thing is that the .NET Framework classes all do but none of mine
> do. Do I have to override the GetType() method of my custom classes?

> Cheers,
> John


> > Don't mind me asking... but do you have any properties (with
> > getter/setters)?
> > Are they public?
> > Does GetFields() return anything?
> > Try the GetProperties(BindingFlags.NonPublic | BindingFlags.Public);



> > > (Sorry for cross-posting, it's important)

> > > I have a class called User (which is self-explanitory) but when I try
to
> > do
> > > something like...
> > > PropertyInfo[] properties = new User().GetType().GetProperties();
> > > int propCount = properties.Length;
> > > ...for some reason propCount comes back 0, which means no properties
> were
> > > found.
> > > If I do the same thing above with a class from the .NET framework or
> from
> > > the same assembly it works fine.
> > > Can someone please help me? I'm trying to do DataMapping but I can't
if
> > this
> > > part won't work.

> > > Cheers,
> > > John



Thu, 13 Jan 2005 02:35:39 GMT  
 I can't reflect a custom class.
The spaces don't make any difference.


Quote:
> Hi,

> Try taking the spaces out between the bindingflags as so:

> >>GetProperties(BindingFlags.NonPublic|BindingFlags.Public);

> HTH

> Ben



Thu, 13 Jan 2005 02:36:43 GMT  
 I can't reflect a custom class.
I SOLVED IT!!

Stupid me, oh well I'm still learning.
I didn't realise that the GetProperties() method only returns the
getter/setter type properties, not all the public members.

Thanks to whoever mentioned getter/setter type properties because I tried it
and it works.

Cheers,
John


Quote:
> (Sorry for cross-posting, it's important)

> I have a class called User (which is self-explanitory) but when I try to
do
> something like...
> PropertyInfo[] properties = new User().GetType().GetProperties();
> int propCount = properties.Length;
> ...for some reason propCount comes back 0, which means no properties were
> found.
> If I do the same thing above with a class from the .NET framework or from
> the same assembly it works fine.
> Can someone please help me? I'm trying to do DataMapping but I can't if
this
> part won't work.

> Cheers,
> John



Thu, 13 Jan 2005 09:19:52 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. 'reflecting messages to the parent from CListCTRL derived class

2. browser address doesn't reflect current web form

3. Help/About doesn't reflect SP3

4. Embedded CPropertySheet - CTabCtrl doesn't reflect EnableWindow(FALSE)

5. Reflected CTL_COLOR message and class derivation

6. 'There was an error reflecting <class>' - Interface properties & XmlSerializer

7. need definition 4 terms: custom class vs class library

8. Problem inherting from custom class inherited from MFC class

9. Problem inherting from custom class inherited from MFC class

10. Class Wizard won't let me derive a class from my class

11. Determining what canned preprocessor symbols are available

12. How to create 'Custom setup'

 

 
Powered by phpBB® Forum Software