Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: Parameters on accessor method "Get"


Message #1 by "James S. Wile" <jsw@l...> on Wed, 13 Nov 2002 14:48:07
I am using the book Beginning ASP.NET 1.0 with VB.NET (ISBN: 1-861007-33-
7). Below is a modified version of the car_object_overload.aspx program 
from chapter 8 in which I specified a parameter on the Get accessor 
method for the Color property.  (The parameter says what language to 
return the color in.)  The chapter did not show any examples of doing 
this, but Exercise 4 at the end of the chapter says the 
following: "Define a new property ConvPrice, whose accessor method Get 
takes two parameters denoting...".  I assume from this that this is 
legal, yet when I tried it, I generated the following error:
 
Compiler Error Message: BC30124: Property without a 'ReadOnly' 
or 'WriteOnly' specifier must provide both a 'Get' and a 'Set'.

Source Error:
 
Line 7:         Private _Gear As Integer
Line 8:      
Line 9:         Public Property Color As String
Line 10:          Get(lang as String)
Line 11:            If lang = "French" Then
 

Here is the relevant portion of the program that generated the error:

Public Class Car
    
       Private _Color As String
           
       Public Property Color As String
         Get(lang as String)
           If lang = "French" Then
             Select Case _Color
               Case "Blue"
                 Return "Bleu"
               Case "Green"
                 Return "Vert"
               Case "White"
                 Return "Blanche"
               Case Else
                 Return "Mon dieu! Je ne sais pas."
             End Select
           Else
             Return _Color
           End If
         End Get
    
         Set(value as String)
           _Color = value
         End Set
       End Property
End Class

    Sub Page_Load()
       Dim MyCar as New Car()
       MyCar.Color = "White"
       Response.Write("Color: " & MyCar.Color("French"))
    End Sub

What is wrong?
Message #2 by brian.lowe@x... on Thu, 14 Nov 2002 08:55:54
> What is wrong?

I'm pretty new to .Net too, but the problem I see in this example is not 
the syntax of what you're doing, it's *what you're doing*.

Isn't the 'pure' object based model one where you'd have an absolute 
value for the colour (with standard get and set methods) and then an 
*additional* method to return the localized string that tells the colour 
in one of a set of recognised languages?

Brian
----@


  Return to Index