473,403 Members | 2,338 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,403 software developers and data experts.

Overriding Properties

Hi, I'm very new to C# and .Net, I've been working with it for about a month.
My experience has been mainly with Delphi 5 (not .Net).

What I'm looking for is for a shortcut way to override a property without actually having to reimplement the get and set methods.
In other words, override the the property without changing the functionality of the base property and without explicitly having to reimplement the get and set methods to make it do so.
The reason I want to do this is because I want to add a property attribute to the overriding class (a database parameter attribute in this case).

For example, instead of this:
[DBParameter(Name = "StaffMemberID")] //<-- My attribute I'm adding to the overriding class

public override Guid Id

{ //<-- Right now, I can only make it work by reimplemententing get and set, which is tedious and annoying.

get { return base.Id; }

set { base.Id = value; }

}

Can I do something like this: (I know this doesn't work, but is there some way to do this?)


[DBParameter(Name = "StaffMemberID")] //<-- My attribute I'm adding to the overriding class

public override Guid Id; // <-- Meaning: No implementation details here, just do the same as the base class.

Nov 17 '05 #1
2 3579
"ESPNSTI" <ES*********@Hotmail.com> a écrit dans le message de news:
OF*************@TK2MSFTNGP15.phx.gbl...
What I'm looking for is for a shortcut way to override a property without actually having to reimplement the get and set methods.


You have been spoilt in Delphi, we have always been able just to redeclare
the property name and promote its visibility at the same time.

I'm sorry, but this C# language has a bit to go before it is as mature as
Delphi :-)

So you will have to write getters and setters because they are part of a C#
property declaration. Also you will not be able to change visibility without
using 'new' on the derived property as it doesn't override, it hides the
original property.

Never mind, at least you haven't got to worry about the lack of the
'implements' directive that I use so much for interface delegation :-((

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #2
ESPNSTI wrote:
Hi, I'm very new to C# and .Net, I've been working with it for about a month.
My experience has been mainly with Delphi 5 (not .Net).

What I'm looking for is for a shortcut way to override a property without actually having to reimplement the get and set methods.
In other words, override the the property without changing the functionality of the base property and without explicitly having to reimplement the get and set methods to make it do so.
The reason I want to do this is because I want to add a property attribute to the overriding class (a database parameter attribute in this case).

For example, instead of this:
[DBParameter(Name = "StaffMemberID")] //<-- My attribute I'm adding to the overriding class

public override Guid Id

{ //<-- Right now, I can only make it work by reimplemententing get and set, which is tedious and annoying.

get { return base.Id; }

set { base.Id = value; }

}

Can I do something like this: (I know this doesn't work, but is there some way to do this?)
[DBParameter(Name = "StaffMemberID")] //<-- My attribute I'm adding to the overriding class

public override Guid Id; // <-- Meaning: No implementation details here, just do the same as the base class.

check this out, I think it is what you are asking for.
http://msdn.microsoft.com/library/de...clrfBasePG.asp
Nov 17 '05 #3

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

Similar topics

2
by: Nick Patavalis | last post by:
Why does the following print "0 0" instead of "0 1"? What is the canonical way to rewrite it in order to get what I obviously expect? class C(object): __val = 0 def set_value(self, val): if...
10
by: Martin Miller | last post by:
I'm trying to create some read-only instance specific properties, but the following attempt didn't work: > class Foobar(object): > pass > > foobar = Foobar() > foobar.x =...
0
by: Nigel Sampson | last post by:
ey all, I'm in the process of creating a method of tracking whenever an objects properties are changed. Since its not possible to alter existing types I decided to used a proxy generated using...
8
by: Edward Diener | last post by:
Is it possible for a derived class to override a property and/or event of its base class ?
5
by: Guy | last post by:
Guys Hope someone can help me! I'm having real problems getting properties I type against a control I have written at design time I have written a control by inheriting from the Button control....
3
by: Helen | last post by:
I have a person class with a name object. The name object has several fields including one called "title". The two classes look something like this: public class name { public string title {...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
4
by: Ray Cassick \(Home\) | last post by:
I am trying to create a generic logging component that will accept an exception object and create a string containing all the properties and their values available for a specific exception. My...
2
by: project | last post by:
Hi every body, Any body can help me the following doubts? 1. what is constructor? 2. what is destructor? 3. what is overriding function. 4. different between structure and array 5. what is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.