473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting Properties and property values of a sealed class

I am using a function to get properies and property values of an object
private string[] ObjPropVals(Object o)
{
Type t = o.GetType();
PropertyInfo[] pia = t.GetProperties();
string[] stra = new string[pia.Length];
for(int i=0; i<pia.Length; i++)
{
stra[i] = pia[i].Name + " " + pia[i].GetValue(o, null);
}
return stra;
}

I would like to use something similar to get static properties of a sealed
class. Any suggestions?

Thanks
SG
Apr 12 '06 #1
3 1893
I leftout some info. I am talking about the classes you can not create an
instance of (private constructors). How can I get static properties and
propery values of such classes?

Thanks
SG

"Gugale at Lincoln" <ph*******@yahoo.com> wrote in message
news:nr******************@newssvr11.news.prodigy.c om...
I am using a function to get properies and property values of an object
private string[] ObjPropVals(Object o)
{
Type t = o.GetType();
PropertyInfo[] pia = t.GetProperties();
string[] stra = new string[pia.Length];
for(int i=0; i<pia.Length; i++)
{
stra[i] = pia[i].Name + " " + pia[i].GetValue(o, null);
}
return stra;
}

I would like to use something similar to get static properties of a sealed
class. Any suggestions?

Thanks
SG

Apr 12 '06 #2
Gugale at Lincoln <ph*******@yahoo.com> wrote:
I leftout some info. I am talking about the classes you can not create an
instance of (private constructors). How can I get static properties and
propery values of such classes?


Use typeof(TypeName) to get a Type, then you can still call
GetProperties. Just pass null as the first parameter to GetValue.

If that doesn't help, could you give us the code you've tried?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 12 '06 #3
That helped! Thank you!

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Gugale at Lincoln <ph*******@yahoo.com> wrote:
I leftout some info. I am talking about the classes you can not create an
instance of (private constructors). How can I get static properties and
propery values of such classes?


Use typeof(TypeName) to get a Type, then you can still call
GetProperties. Just pass null as the first parameter to GetValue.

If that doesn't help, could you give us the code you've tried?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Generic Usenet Account | last post by:
A lot has been said in this newsgroup regarding the "evil" set/get accessor methods. Arthur Riel, (of Vanguard Training), in his class, "Heuristis for O-O Analysis & Design", says that there is...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
8
by: Chuck Bowling | last post by:
Is there any justification - from an OOP perspective - for wrapping an attribute in a Property beyond the ability to restrict access? private int myInt; public int MyInt { get { return...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
8
by: Joel Reinford | last post by:
I would like to build a class that has properties which can be accessed by string names or index numbers in the form of MyClass.Item("LastName"). The string names or item index values would be...
11
by: LDD | last post by:
What is the real benefit of using Properties? You can declare class variables either public/private. I'm not sure I understand the true benefit. Especially if you are reading from/writing to...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
6
by: WT | last post by:
Hello, Using VS2005. I have an assembly library that can be called from a Web site asp.net application or from a winform application. From this library I need to retrieve a path using simply a...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.