By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,921 Members | 1,949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,921 IT Pros & Developers. It's quick & easy.

Strange behavior - Overloaded Property and Enum parameter - Bug?

P: n/a
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
HorizontalOffset = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByVal 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(Optional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equals(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.Offsets(EOffsetTypes.HorizontalOffset) = 7.0

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

'Correct ArrayList2(1) is updated.
objBlock.Offsets(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.Offsets(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
Share this Question
Share on Google+
3 Replies


P: n/a
"Arnold Schrijver" <ar*************************@2organize.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
HorizontalOffset = 0
VerticalOffset = 1
End Enum

'Update ArrayList with Horz/Vertical offsets, that are always
present.
Protected WriteOnly Property BlockOffset(ByVal 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(Optional ByVal offsetIndex
As Integer = Nothing) As Double
Set(ByVal offset As Double)

If offsetIndex.Equals(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.Offsets(EOffsetTypes.HorizontalOffset) = 7.0

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

'Correct ArrayList2(1) is updated.
objBlock.Offsets(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.Offsets(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

P: n/a
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*************************@2organize.com> wrote in message
news:e1***************@TK2MSFTNGP09.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(Class1.Foo.Goo) = "0 Enum"
objTest.Test(Class1.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****************@TK2MSFTNGP09.phx.gbl...

<SNIP/>
Nov 21 '05 #3

P: n/a
"Arnold Schrijver" <ar*************************@2organize.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 discussion thread is closed

Replies have been disabled for this discussion.