Overriding Properties

E

ESPNSTI

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.
 
J

Joanna Carter \(TeamB\)

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
 
E

Eugene Vital

ESPNSTI said:
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/default.asp?url=/library/en-us/csref/html/vclrfBasePG.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top