473,597 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange behavior - Overloaded Property and Enum parameter - Bug?

I wrote a program that draws items to the screen and maintains a set of
Offset values.
There was a bug in the code, because objects were positioned wrongly. While
debugging
I found some peculiar behavior with the overloaded Property Offsets:

In class CanvasBlock:
------------------------------

Public Enum EOffsetTypes
HorizontalOffse t = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByV al offsetType As
EOffsetTypes) As Double
Set(ByVal offset As Double)
'Add new value to ArrayList1 at specified index (=
CInt(offsetType )).
End Set
End Property

'Store any additional Offsets in a separate ArrayList. Create
additional entries as needed.
Protected WriteOnly Property BlockOffset(Opt ional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equ als(Nothing) = True Then
'Add new value to ArrayList2
Else
'Add new value to ArrayList2 at specified offsetIndex .
End If
End Set
End Property

In the calling code:
------------------------------

'Correct. ArrayList1(0) is updated.
objBlock.Offset s(EOffsetTypes. HorizontalOffse t) = 7.0

'Correct. ArrayList1(1) is updated.
objBlock.Offset s(EOffsetTypes. VerticalOffset) = 7.0

'Correct ArrayList2(1) is updated.
objBlock.Offset s(1) = 7.0

'Incorrect!! ArrayList1(0) is updated. The first overloaded method
with the Enum signature is called.
'Since the previous call succeeded, I would expect this call to
succeed as well. Strange? A bug?
objBlock.Offset s(0) = 7.0

Am I doing something wrong here? Can .NET not differentiate between
signatures with Integer and
Enums (which are basically also integer values), or is this a bug in .NET?

Cheers,

Arnold Schrijver.
Nov 21 '05 #1
3 1852
"Arnold Schrijver" <ar************ *************@2 organize.com> schrieb:
I wrote a program that draws items to the screen and maintains a set of
Offset values.
There was a bug in the code, because objects were positioned wrongly.
While
debugging
I found some peculiar behavior with the overloaded Property Offsets:

In class CanvasBlock:
------------------------------

Public Enum EOffsetTypes
HorizontalOffse t = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByV al offsetType As
EOffsetTypes) As Double
Set(ByVal offset As Double)
'Add new value to ArrayList1 at specified index (=
CInt(offsetType )).
End Set
End Property

'Store any additional Offsets in a separate ArrayList. Create
additional entries as needed.
Protected WriteOnly Property BlockOffset(Opt ional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equ als(Nothing) = True Then
'Add new value to ArrayList2
Else
'Add new value to ArrayList2 at specified offsetIndex .
End If
End Set
End Property

In the calling code:
------------------------------

'Correct. ArrayList1(0) is updated.
objBlock.Offset s(EOffsetTypes. HorizontalOffse t) = 7.0

'Correct. ArrayList1(1) is updated.
objBlock.Offset s(EOffsetTypes. VerticalOffset) = 7.0

'Correct ArrayList2(1) is updated.
objBlock.Offset s(1) = 7.0

'Incorrect!! ArrayList1(0) is updated. The first overloaded method
with the Enum signature is called.
'Since the previous call succeeded, I would expect this call to
succeed as well. Strange? A bug?
objBlock.Offset s(0) = 7.0

Am I doing something wrong here? Can .NET not differentiate between
signatures with Integer and
Enums (which are basically also integer values), or is this a bug in .NET?

I am not able to repro this behavior with .NET 1.0 using the code below:

\\\
Public Enum Foo
Goo = 0
Baz = 1
End Enum

Public WriteOnly Property Test(Optional ByVal i As Integer = 0) As Object
Set(ByVal Value As Object)
Debug.WriteLine ("'Test(Integer )'")
End Set
End Property

Public WriteOnly Property Test(ByVal i As Foo) As Object
Set(ByVal Value As Object)
Debug.WriteLine ("'Test(Foo) '")
End Set
End Property
..
..
..
Test(1) = 1
Test(Foo.Baz) = 1
///

Output:

---
'Test(Integer)'
'Test(Foo)'
---

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
I found that the information is indeed a bug, but then in the VB language. An excellent
explanation can be found on Rob Gruen's weblog:
http://weblogs.asp.net/robgruen/arch.../26/97104.aspx

There is also an extensive discussion on this issue on dotnet247.com:
http://www.dotnet247.com/247referenc...56/284220.aspx
"Arnold Schrijver" <ar************ *************@2 organize.com> wrote in message
news:e1******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi,

Given your code, I could reproduce the strange behavior again! I added the VB project
in the attached zip-file.

With your code in Class1 these calls:

Dim objTest As New Class1

objTest.Test(0) = "0 Integer"
objTest.Test(1) = "1 Integer"
objTest.Test(Cl ass1.Foo.Goo) = "0 Enum"
objTest.Test(Cl ass1.Foo.Baz) = "1 Enum"

Result in:

'Test(Foo)'
'Test(Integer)'
'Test(Foo)'
'Test(Foo)'

I am using Visual Studio 2003 (v. 7.1.3088) with .NET Framework 1.1 (v. 1.1.4322 SP1)
on Windows 2000 SP4 (v. 5.00.2195)

As a temporary workaround to fix the code I appended a dummy Boolean to the overloaded
enum Method, to create a method signature that differs more significantly. This works, but is
not pretty.

Thanks for your response!

Cheers,

Arnold.

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:e8******** ********@TK2MSF TNGP09.phx.gbl. ..

<SNIP/>
Nov 21 '05 #3
"Arnold Schrijver" <ar************ *************@2 organize.com> schrieb:
I found that the information is indeed a bug, but then in the VB language.
An excellent
explanation can be found on Rob Gruen's weblog:
http://weblogs.asp.net/robgruen/arch.../26/97104.aspx

There is also an extensive discussion on this issue on dotnet247.com:
http://www.dotnet247.com/247referenc...56/284220.aspx


Thank you for sharing these interesting links. In the meantime I was able
to repro the behavior in VB.NET 2002 too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

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

Similar topics

36
3422
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested print 2.
5
6877
by: Andy Jarrell | last post by:
I'm trying to inherit from a specific class that has an overloaded operator. The problem I'm getting is that certain overloaded operators don't seem to come with the inheritance. For example: // TestA.h --------------------------------------- #include <iostream> enum Aval { FIRST_VALUE,
6
2547
by: Mårten Herberthson | last post by:
Introduction: As we all know, values of any class may be assigned to a reference of a superclass. This is simple polymorphism. So if you have a class A and a class B that inherits from A you can write a method that returns an instance of B and assign that to a reference of type A. (Trivial) Problem:
9
1647
by: Karahan Celikel | last post by:
Here are three simple classes: class A { public void DoIt(B b) { DoSomething(b); } public void DoSomething(B b) {
0
1502
by: student | last post by:
In Summary: Create an object - dont set one of its Enum Type properties and make sure it does not appear in XML Object Serialization. Strings function as hoped for but Enums do not Heres my problem broken down to simplest form I have the following ENUM ----------------------------------------------
6
2256
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to the same method (aka delegate?). I use the Tag property within this method to determine what user action is taking place. Very simple: When adding toolbar button: tbButton.Click += new...
4
4032
by: Pritcham | last post by:
Hi all I've got a number of classes already developed (basic entity classes) like the following: Public Class Contact Private _firstname as String Private _age as Integer Public Property FirstName As String
1
2970
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and the second is a custom VB6 COM component. So I was reading about AspCompat=true and it seemed like it would be a good fit for our app. From what I can tell both of the COM components that we are using are STA and we are creating the components in...
2
3510
by: JB | last post by:
Hi All, I'm pulling my hair over this and could really do with a bit of help. I'm using various different enums as bit fields and I'd like to create a set of generic Functions or Subs to manipulate the bitfields. For instance: <Flags()_ Enum ActionFlags As Byte
0
7959
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
7883
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
8263
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...
1
8021
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,...
0
8254
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 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...
0
6677
agi2029
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...
0
3876
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
3917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1492
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.