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(Nam e = "StaffMemberID" )] //<-- My attribute I'm adding to the overriding class
public override Guid Id
{ //<-- Right now, I can only make it work by reimplemententi ng 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(Nam e = "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. 2 3604
"ESPNSTI" <ES*********@Ho tmail.com> a écrit dans le message de news: OF************* @TK2MSFTNGP15.p hx.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
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(Nam e = "StaffMemberID" )] //<-- My attribute I'm adding to the overriding class
public override Guid Id
{ //<-- Right now, I can only make it work by reimplemententi ng 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(Nam e = "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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 val < 0 : self.__val = 0
else : self.__val = val
def get_value(self):
return self.__val
|
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 = property(fget=lambda: 42)
>
> print "foobar.x:", foobar.x
|
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
Reflection.Emit which inherits from the object needed
Person p = (Person)ProxyBuilder.Construct(typeof(Person));
|
by: Edward Diener |
last post by:
Is it possible for a derived class to override a property and/or event of
its base class ?
|
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. I am trying to add a feature whereby the control changes to a different color when the mouse floats over it, or when the button has the focus. The color changing works if the 'LightColor' is set at runtime in code. However, if I draw the control on...
| |
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 {
// get set code here
}
}
|
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 when the Poodle is upcast to
the Dog (in its wildest dreams) it then says "bow wow" where the bernard
always says "woof" (see code). Basically, it appears that I'm hiding the
poodle's speak method from everything except the poodle.
Why would I...
|
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 intent here is try to create a generic function that will be able to:
- Take a an object of type Exception...
- Iterate through all the properties the object has...
- Add the property names to a stringbuilder...
- Call each of the properties and...
|
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 objected oriented
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |