Web Log di Adrian Florea

"You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
posts - 440, comments - 2715, trackbacks - 3944

My Links

Archives

Post Categories

Image Galleries

.RO Blogs

.RO People

.RO Sites

Blogs

Furls

Links

vinCitori

Esempi errati nelle specifiche VB .NET

Il seguente snippet è preso dal paragrafo 9.6.2 delle specifiche VB .NET:

Imports System

Class Raiser
  Public Event Constructed()

  Public Sub New()
    RaiseEvent Constructed()
  End Sub
End
Class

Module
Test
  Private WithEvents x As Raiser

  Private Sub HandleConstructed() Handles x.Constructed
    Console.WriteLine("Constructed")
  End Sub

  Public
Sub Main()
    x = New Raiser
  End Sub
End
Module

Non mi spiego come un errore così elementare (vedi la Reference: "Non-shared events should not be raised within the constructor of the class in which they are declared. Although such events do not cause runtime errors, they may fail to be caught by associated event handlers") possa essere fatto proprio da Paul Vick... Putroppo non si ferma qui ma continua con lo stesso errore anche nel paragrafo 10.5.1:

Imports System

Class Raiser
  Public Event Constructed(ByVal Count As Integer)

  Public Sub New()
    Static CreationCount As Integer = 0

    CreationCount += 1
    RaiseEvent Constructed(CreationCount)
  End Sub
End
Class

Module
Test
  Private WithEvents x As Raiser

  Private Sub Constructed(ByVal Count As Integer) Handles x.Constructed
    Console.WriteLine("Constructed instance #" & Count)
  End Sub

  Public
Sub Main()
    x = New Raiser ' Causes "Constructed instance #1" to be printed.
   
x = New Raiser ' Causes "Constructed instance #2" to be printed.
   
x = New Raiser ' Causes "Constructed instance #3" to be printed.
 
End Sub
End
Module

Nessuno dei due snippet stampa qualcosa a console.

Trovare codice errato nelle specifiche di un linguaggio mi lascia un po' senza parole.

(Aggiornamento 31/03/05): Errato anche l'esempio del paragrafo 9.2.6 (a parte il simpatico "Public End Sub"...). In pratica sono errati TUTTI gli esempi in cui appare RaiseEvent.

(Aggiornamento 02/04/05): Ho scritto ieri sera a Paul.

Print | posted on giovedì 31 marzo 2005 04:42 | Filed Under [ Carillon .NET Bugs? ]

Powered by:
Powered By Subtext Powered By ASP.NET