473,412 Members | 3,015 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,412 software developers and data experts.

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 5519
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: kepes.krisztian | last post by:
Hi ! I want to create a property that can use parameter(s). In Delphi I can create same thing (exm: Canvas.Pixel -> Canvas.GetPixel(self,X,Y):integer; Canvas.SetPixel(self,X,Y,Color::integer); ...
11
by: Laszlo Zsolt Nagy | last post by:
My problem is about properties and the virtuality of the methods. I would like to create a property whose get and set methods are virtual. I had the same problems in Delphi before and the solution...
1
by: Ron Adam | last post by:
I was trying to see if I can implement property groups so I can set and pass arguemts as dictionaries. I think this will simplify interfacing to multiple objects and funtions that use a lot of...
8
by: Herve Bocuse | last post by:
Hi, I'm just wondering what are the guidelines for using a Property or a pair of get/set methods related to a member variable ? What do yu guys do ? Thank you Herve
13
by: Peter Kirk | last post by:
Hi there, can someone tell me what exactly a "property" is in a C# class? As far as I can see it is "two methods" - ie a getter and a setter for an instance variable. What is the difference...
7
by: none | last post by:
I'm trying to implement a simple repeateable property mechansism so I don't have to write accessors for every single instance variable I have. ------------ classMyObject: def __init__ (self):...
6
by: Peter Franks | last post by:
Is it possible to deserialize a class that has a public property w/ a setter, but no getter? I'm not finding anything that would allow this -- Presuming that is is NOT possible, what are the...
7
by: Curious | last post by:
Hi, I have a C# class that contains a property defined as follows: public bool bRunTwice { get { return bRunTwice; } set { bRunTwice = value; } }
4
by: Yin99 | last post by:
I programmed JAVA for a while and starting C#, and was experimenting with "Properties". Question I have, is what is the benefit? JAVA does not have the concept of properties, so what is JAVA...
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?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.