Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Sign In| Join
Last post Sep 23, 2008 06:43 AM by bhadelia.imran
Member
4 Points
9 Posts
Sep 22, 2008 02:13 AM|LINK
Hi everyone,
how could i get the list of properties of my subclass only.. and not getting the properties of my ParentClass.
i know i could do this using line of code below but my problem is I also get the properties of my ParentClass which i dont need to.
PropertyInfo[] properties = typeof(MysubClass).GetProperties();
I just need to get the properties of my subclass, not including properties of my ParentClass..
Can you help me guys..
Thanks.
Star
8370 Points
1283 Posts
Sep 22, 2008 03:30 AM|LINK
genpopo,
You want .GetProperties(BindingFlags.DeclaredOnly);
James
Sep 22, 2008 03:41 AM|LINK
I've tried it but I didnt get any result. I've made a work around if the declaredType is equal to my baseclass name then ill skip it.. but if there's a better way to do this.. I will appreciate it..
Thanks for your reply. :)
Contributor
3191 Points
533 Posts
Sep 22, 2008 04:24 AM|LINK
Try this
var prop = from p in typeof(B).GetProperties() where p.DeclaringType == typeof(B) select p;
in prop you will have only B's property
Have func with LINQ
Sep 22, 2008 05:48 AM|LINK
this is also cool.. thanks bro
Sep 23, 2008 06:43 AM|LINK
That is really good question.
genpopo
Member
4 Points
9 Posts
How to get Property name of a subclass?
Sep 22, 2008 02:13 AM|LINK
Hi everyone,
how could i get the list of properties of my subclass only.. and not getting the properties of my ParentClass.
PropertyInfo[] properties = typeof(MysubClass).GetProperties();vgiambattista
Star
8370 Points
1283 Posts
Re: How to get Property name of a subclass?
Sep 22, 2008 03:30 AM|LINK
genpopo,
You want .GetProperties(BindingFlags.DeclaredOnly);
James
MVP Client App Dev
genpopo
Member
4 Points
9 Posts
Re: How to get Property name of a subclass?
Sep 22, 2008 03:41 AM|LINK
I've tried it but I didnt get any result. I've made a work around if the declaredType is equal to my baseclass name then ill skip it.. but if there's a better way to do this.. I will appreciate it..
Thanks for your reply. :)
bhadelia.imran
Contributor
3191 Points
533 Posts
Re: How to get Property name of a subclass?
Sep 22, 2008 04:24 AM|LINK
Try this
var prop = from p in typeof(B).GetProperties() where p.DeclaringType == typeof(B) select p;in prop you will have only B's property
Have func with LINQ
[MCTS]
Born to fly High
http://knowledgebaseworld.blogspot.com/
genpopo
Member
4 Points
9 Posts
Re: How to get Property name of a subclass?
Sep 22, 2008 05:48 AM|LINK
this is also cool.. thanks bro
bhadelia.imran
Contributor
3191 Points
533 Posts
Re: How to get Property name of a subclass?
Sep 23, 2008 06:43 AM|LINK
That is really good question.
You can check it out on my blog http://knowledgebaseworld.blogspot.com/2008/09/how-to-get-property-list-only-of.html[MCTS]
Born to fly High
http://knowledgebaseworld.blogspot.com/