473,796 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem to override a Property

Hello.
I provided a class, which derives from the class DataView.
The only thing, which I would like to do in this class am to overwrite the
Property COUNT.
I wars it however simply not. I get always following message from the
compiler, although COUNT of the DataView (according to MSDN) is virtual.
the element ' System.Data.Dat aView.Count.get ' cannot be overwritten,
because as virtually, abstract or do not overwrite it is marked
Can someone help me?
Thanks Thomas
Nov 15 '05 #1
7 2075
Thomas Kehl <t.****@heeb.co m> wrote:
I provided a class, which derives from the class DataView.
The only thing, which I would like to do in this class am to overwrite the
Property COUNT.
I wars it however simply not. I get always following message from the
compiler, although COUNT of the DataView (according to MSDN) is virtual.


I believe this is a bug in the documentation. If you look at the type
with ILDASM or Reflector, you'll see it's not actually virtual.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
Hi Jon,
when I look into System.Data with the Objectbrowser, I see, that the
definition of the Property is the fallowing:

public virtual new int Count [ get]

I think, I should be able to override it, should'nt I?

regards
thomas
"Jon Skeet" <sk***@pobox.co m> schrieb im Newsbeitrag
news:MP******** *************** *@news.microsof t.com...
Thomas Kehl <t.****@heeb.co m> wrote:
I provided a class, which derives from the class DataView.
The only thing, which I would like to do in this class am to overwrite the Property COUNT.
I wars it however simply not. I get always following message from the
compiler, although COUNT of the DataView (according to MSDN) is virtual.


I believe this is a bug in the documentation. If you look at the type
with ILDASM or Reflector, you'll see it's not actually virtual.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Thomas Kehl <t.****@heeb.co m> wrote:
when I look into System.Data with the Objectbrowser, I see, that the
definition of the Property is the fallowing:

public virtual new int Count [ get]

I think, I should be able to override it, should'nt I?


I think it's taking that from the documentation rather than from the
assembly itself - it's certainly *not* virtual. The IL in ILDASM shows

..method public hidebysig newslot specialname virtual final
instance int32 get_Count() cil managed

and although "virtual" appears there, so does "final". It's all a bit
confusing, but I'm sure the upshot is that it's not virtual, I'm afraid
:(

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
The short answer is that MSDN and the object browser are wrong: the
property is not virtual.

The longer answer is that the DataView.Count property is non-virtual, and
is part of the implementation of the IComponent interface
(IComponent.Cou nt). C# allows non-virtual interface implemenations, but
the CLR requires that all methods which implement interfaces be virtual.
So the compiler emits this in metadata as "newslot virtual final." So it
has the virtual flag set in metadata, but is final so that you cannot
override it.

-Mark
--
Mark Andersen, Visual C# Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
--------------------
From: Jon Skeet <sk***@pobox.co m>
Subject: Re: Problem to override a Property
Date: Thu, 25 Sep 2003 19:28:25 +0100
Message-ID: <MP************ ************@ne ws.microsoft.co m>
References: <ud************ **@TK2MSFTNGP11 .phx.gbl> <MP************ ************@ne ws.microsoft.co m>
<OR************ **@TK2MSFTNGP11 .phx.gbl>MIME-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: MicroPlanet Gravity v2.60
Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
NNTP-Posting-Host: cpc3-rdng5-6-0-cust143.winn.ca ble.ntl.com 81.103.154.143
Lines: 1
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP10.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.csharp:1873 72
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.csharp

Thomas Kehl <t.****@heeb.co m> wrote:
when I look into System.Data with the Objectbrowser, I see, that the
definition of the Property is the fallowing:

public virtual new int Count [ get]

I think, I should be able to override it, should'nt I?


I think it's taking that from the documentation rather than from the
assembly itself - it's certainly *not* virtual. The IL in ILDASM shows

.method public hidebysig newslot specialname virtual final
instance int32 get_Count() cil managed

and although "virtual" appears there, so does "final". It's all a bit
confusing, but I'm sure the upshot is that it's not virtual, I'm afraid
:(

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 15 '05 #5

"Mark Andersen [MSFT]" <ma****@online. microsoft.com> wrote in message
news:7k******** ******@cpmsftng xa06.phx.gbl...
The short answer is that MSDN and the object browser are wrong: the
property is not virtual.

The longer answer is that the DataView.Count property is non-virtual, and
is part of the implementation of the IComponent interface
(IComponent.Cou nt). C# allows non-virtual interface implemenations, but
the CLR requires that all methods which implement interfaces be virtual.
So the compiler emits this in metadata as "newslot virtual final." So it
has the virtual flag set in metadata, but is final so that you cannot
override it.


So C# does not allow a method to be declared "virtual sealed", but will
generate the equivalent in IL for methods that are not declared virtual.
Interesting :-)
Nov 15 '05 #6
Mike Schilling <ms************ *@hotmail.com> wrote:
So C# does not allow a method to be declared "virtual sealed", but will
generate the equivalent in IL for methods that are not declared virtual.
Interesting :-)


Yes - as far as I can see, the CLR itself has some very odd terminology
in terms of "virtual" - it requires a method to be "virtual" to end up
being the resolution of a virtual call, even if it's not virtual in the
sense of being overridable (which is the sense the C# specification
uses). I don't think it's helping the discussion on what virtual means
:(

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7

"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mike Schilling <ms************ *@hotmail.com> wrote:
So C# does not allow a method to be declared "virtual sealed", but will
generate the equivalent in IL for methods that are not declared virtual.
Interesting :-)


Yes - as far as I can see, the CLR itself has some very odd terminology
in terms of "virtual" - it requires a method to be "virtual" to end up
being the resolution of a virtual call, even if it's not virtual in the
sense of being overridable (which is the sense the C# specification
uses). I don't think it's helping the discussion on what virtual means
:(


If I had to guess (and I do, since I'm too lazy to look it up :-), I'd
suspect that to the CLR "virtual" means "occupies a slot in the virtual
function table". The fact that the only difference between "virtual" and
"override" methods in C# is that the former generates the "newslot" CLR
keyword encourages me in this belief.
Nov 15 '05 #8

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

Similar topics

3
3152
by: Omer van Kloeten | last post by:
The Top Level Design: The class Base is a factory class with a twist. It uses the Assembly/Type classes to extract all types that inherit from it and add them to the list of types that inherit from it. During run time, using a static method, the class creates an instance of the derived class using the Activator class and returns it. This design pattern is very similar to the design pattern applied by the Assembly class. The twist is...
5
2946
by: jorfei | last post by:
I have written a component with a property IPAdrress of type System.Net.IPAddress. To ease the configuration of the component at design time, I have written a type converter for the type System.Net.IPAddress. The type System.Net.IPAddress, as you know, is provided by Microsoft and I have no choice but to apply the type converter on the IPAddress property of the component itself (instead of the type System.Net.IPAddress). All normal...
1
437
by: SpookyET | last post by:
I have thought that you can disable a set or a get when you override a virtual property. I guess that I was wrong. The code below compiles and doesn't throw the exceptions that I have expected. It calls the base accessor. using System; namespace Test { public abstract class MetaDataFile
1
4405
by: Polo | last post by:
Hi, I have a Custom ExpandableTypeConverter (that show the property of a object readonly) Some properties of this sub object have the Browsable(false) attribute but in the PropertyGrid these properties are showed. public class Test { //....
0
1473
by: Jongmin | last post by:
I met a problem when implementing IBindingList interface. I made CustomerList class, copied from MSDN, to implement CollectionBase and IBindingList. My problem took place after setting Datasource and adding new data. The system throw the following exception when I run "button1_Click", A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll Additional information: Specified argument...
2
2517
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a pointer or reference to a derived type of the base class's return type. In .NET the overridden virtual function is similar, but an actual parameter of the function can be a derived reference from the base class's reference also. This dichotomy...
0
1562
by: michael | last post by:
Hi. I have a problem using the CollectioEditor. In my custom control I have a public property that returns ItemList. ItemList is inherited from CollectionBase and contains very simple items called "TestItem" that are inherited from Control. i have added,To the TestItem class, a proprety called "ItemIcon", and I added to this property the attribute Editor(typeof(ImageUrlEditor)....). In design-time, I can access the "ItemList" property...
0
2798
by: Kristopher Wragg | last post by:
Hi, I'm having a problem with XMLSerializer, I have classes like the following: public abstract class EulerObject { private Rectangle rect; private string guid = "";
0
5660
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
0
9685
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, 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...
0
9535
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,...
0
10465
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, 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...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7558
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 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...
0
5453
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
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
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.