473,388 Members | 1,198 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,388 software developers and data experts.

Accessing Properties on an object with special attributes

Hi,

after searching and testing for hours, im off with that.

Maybe you have a snippet or link for me.
I have a class with properties. Some of the properties (not all) have a
custom attribute. Now i want to call a method which prints out the values
of the properties with the custom attributes, and only these values.

Howto find out which Properties (Name) have those attributes (Reflection) is
ok, but how would i access a concrete existing object and get the value of
a property, where i have only the reflected name from.
Thanks in advance

Thorsten

Jul 18 '06 #1
4 1691
Get a System.Reflection.PropertyInfo object for the properties you want
to manipulate. Then use the PropertyInfo.GetValue and
PropertyInfo.SetValue methods.

I'm sure a quick search for "PropertyInfo.SetValue" will point you to
what you're looking for.

Jul 18 '06 #2
....You would pass the instance of the object from which you wanted to
read values to the GetValue method.

Jul 18 '06 #3
Thorsten Viel <th***********@gmx.dewrote:
after searching and testing for hours, im off with that.

Maybe you have a snippet or link for me.
I have a class with properties. Some of the properties (not all) have a
custom attribute. Now i want to call a method which prints out the values
of the properties with the custom attributes, and only these values.

Howto find out which Properties (Name) have those attributes (Reflection) is
ok, but how would i access a concrete existing object and get the value of
a property, where i have only the reflected name from.
Use PropertyInfo.GetValue. Chances are you'll already have the
PropertyInfo from the way you've found the properties with the
appropriate attribute.

--
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
Jul 18 '06 #4
allfyre wrote:
...You would pass the instance of the object from which you wanted to
read values to the GetValue method.

Works lika a charm. Thanks to all of you.
Jul 18 '06 #5

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

Similar topics

4
by: Mike Clair | last post by:
Hey, I'm having an issue with CSS, JS and the DOM. It's gonna drive me batty. I am trying to access the properties of a layer in JS which have been initially set in an external CSS. The problem...
3
by: Martin Montgomery | last post by:
I have, for example, a property called myProperty. I would like, when using a property grid to display the property name as "My Property". Is this possible. Is there an attribute etc Thank ...
2
by: damonf | last post by:
I'm currently trying to add an ASP hyperlink to a template column in a datagrid. The normal hyperlink column doesn't give me the ability to add attributes to the item. In my grid there are four...
9
by: Mark Jones | last post by:
This rather cryptic title is actually a .net oop noob question. Example: My customer object has a public property called .name which is a string. I would like to be able to reference...
2
by: EP | last post by:
I'm looking for a method by which to access Windows files metadata and have not been able to find anything in the standard modules or via Google - what is the standard approach? Shamefully I...
3
by: redefined.horizons | last post by:
I've been reading about Python Classes, and I'm a little confused about how Python stores the state of an object. I was hoping for some help. I realize that you can't create an empty place holder...
3
by: David Lozzi | last post by:
Howdy, I'm using a PlaceHolder to dynamically display a user control based on a users selection. This part works great. However how do I get to the properties of that user control? I have public...
3
by: Beorne | last post by:
In the classes I develop my attributes are always private and are exposed using properties. directly or to access the attributes using the properties? Does "wrapper" setter/getter properties...
5
by: feli.hp | last post by:
Hello all, Imaybe someone can help me with this question. Is there a direct way of accessing an object instance, if all I know is the value of one of its attributes? The object is part of a...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.