PC Review


Reply
Thread Tools Rate Thread

Adding a Property to a Properties getter and setter

 
 
Jimbo
Guest
Posts: n/a
 
      8th Feb 2005
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.

 
Reply With Quote
 
 
 
 
Sean Hederman
Guest
Posts: n/a
 
      8th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>



 
Reply With Quote
 
Bob Grommes
Guest
Posts: n/a
 
      8th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>



 
Reply With Quote
 
RCS
Guest
Posts: n/a
 
      8th Feb 2005
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" <(E-Mail Removed)> wrote in message
news:cuambh$dgs$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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.
>>

>
>



 
Reply With Quote
 
Sean Hederman
Guest
Posts: n/a
 
      8th Feb 2005
Good point. There's ALWAYS another way to skin a cat ;D

"RCS" <(E-Mail Removed)> wrote in message
newsj5Od.27187$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:cuambh$dgs$(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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.
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hooking into a getter or setter of .Net class Josh Valino Microsoft C# .NET 2 8th Aug 2008 08:19 PM
getter and setter methods in C#? =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= Microsoft C# .NET 3 6th Nov 2006 11:09 AM
Deserialize property w/ setter but no getter in 2.0??? Peter Franks Microsoft Dot NET Framework 6 10th Oct 2006 04:56 AM
getter/setter with no body kronrn@yahoo.com Microsoft C# .NET 5 21st Aug 2006 02:37 AM
problem with getter and setter not working Adam Sandler Microsoft ASP .NET 12 26th May 2006 05:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:13 AM.