469,086 Members | 1,187 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Adding a Property to a Properties getter and setter

I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".

Currently, the getter for the property does some data manipulation
before it returns the value. I wanted to add another getter to this
property that would returnt the "Raw" value (what is stored in _name).
Example:
myObject.Name.Raw --returns the raw data

Any ideas would be very helpful. Thanks in advance.

Nov 16 '05 #1
4 5181
Either:
a) Wrap the returned item into another class which has a Raw property and a
Value property.
or
b) Create a separate getter: myObject.NameRaw

"Jimbo" <jc****@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".

Currently, the getter for the property does some data manipulation
before it returns the value. I wanted to add another getter to this
property that would returnt the "Raw" value (what is stored in _name).
Example:
myObject.Name.Raw --returns the raw data

Any ideas would be very helpful. Thanks in advance.

Nov 16 '05 #2
First off, you don't have a property called "_name". You have a class
member or field called "_name" which you are exposing with a property called
"Name".

No property can have more than one getter and/or setter. If you want to
expose the raw value separately then you have to create another property
with a different name, such as RawName. There are no limitations about
where a property getter derives the values it returns, so multiple
properties can access the same class member if needed.

The syntax you describe, myObject.Name.Raw, would require that Name expose a
class or structure with a property of its own called Raw. And then your
doctored property would have to be exposed in the same way, e.g.,
myObject.Name.Doctored, since Name would only return a reference to the
class instance that implements Name.

--Bob

"Jimbo" <jc****@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".

Currently, the getter for the property does some data manipulation
before it returns the value. I wanted to add another getter to this
property that would returnt the "Raw" value (what is stored in _name).
Example:
myObject.Name.Raw --returns the raw data

Any ideas would be very helpful. Thanks in advance.

Nov 16 '05 #3
RCS
Or.. make it an overloaded method (assuming Processed() is a function that
processes the raw value into a finished value):

public string Name(bool ReturnRaw)
{
if ( ReturnRaw )
return _Name;
else
return Processed(_Name);
}
public string Name()
{
return Name(false);
}
"Sean Hederman" <us***@blogentry.com> wrote in message
news:cu**********@ctb-nnrp2.saix.net...
Either:
a) Wrap the returned item into another class which has a Raw property and
a Value property.
or
b) Create a separate getter: myObject.NameRaw

"Jimbo" <jc****@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".

Currently, the getter for the property does some data manipulation
before it returns the value. I wanted to add another getter to this
property that would returnt the "Raw" value (what is stored in _name).
Example:
myObject.Name.Raw --returns the raw data

Any ideas would be very helpful. Thanks in advance.


Nov 16 '05 #4
Good point. There's ALWAYS another way to skin a cat ;D

"RCS" <rs****@gmail.com> wrote in message
news:pj*******************@newssvr19.news.prodigy. com...
Or.. make it an overloaded method (assuming Processed() is a function that
processes the raw value into a finished value):

public string Name(bool ReturnRaw)
{
if ( ReturnRaw )
return _Name;
else
return Processed(_Name);
}
public string Name()
{
return Name(false);
}
"Sean Hederman" <us***@blogentry.com> wrote in message
news:cu**********@ctb-nnrp2.saix.net...
Either:
a) Wrap the returned item into another class which has a Raw property and
a Value property.
or
b) Create a separate getter: myObject.NameRaw

"Jimbo" <jc****@gmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I am sort of new to C#. Currently have a private property called
"_name" in a class. I have written a public getter and setter routine
for it called "Name".

Currently, the getter for the property does some data manipulation
before it returns the value. I wanted to add another getter to this
property that would returnt the "Raw" value (what is stored in _name).
Example:
myObject.Name.Raw --returns the raw data

Any ideas would be very helpful. Thanks in advance.



Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by kepes.krisztian | last post: by
11 posts views Thread by Laszlo Zsolt Nagy | last post: by
1 post views Thread by Ron Adam | last post: by
8 posts views Thread by Herve Bocuse | last post: by
13 posts views Thread by Peter Kirk | last post: by
7 posts views Thread by none | last post: by
4 posts views Thread by Yin99 | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.