In VBScript, alcuni oggetti incorporati utilizzano una proprietà senza nome. Alcuni esempi:Proprietà predefinita senza nome
Set Dict = Server.CreateObject("Scripting.Dictionary")
Set RS = GetEmloyeesRecordSet()
Dict("Beer") = "Tasty" ' Same as Dict.Item("Beer") = "Tasty"
Dict("Crude Oil") = "Gross" ' Same as Dict.Item("Crude Oil") = "Gross"
Response.Write "The First Employee Is: " & RS("Name") ' Same as RS.Fields("Name")
Come posso utilizzare la stessa sintassi nelle mie classi?
UPDATE
Ecco un lavoro, ad esempio stand-alone di come fare questo, un semplice wrapper per Scripting.Dictionary. Notare l'uso di "Let" per consentire la sintassi d ("chiave") = "valore". Naturalmente il merito va a Thom per aver fornito la risposta.
<%
Class DictWrapper
Private Dict
Private Sub Class_Initialize()
Set Dict = Server.CreateObject("Scripting.Dictionary")
End Sub
Private Sub Class_Terminate()
Set Dict = Nothing
End Sub
Public Property Get Count
Count = Dict.Count
End Property
Public Default Property Get Item(Key)
Item = Dict(Key)
End Property
Public Property Let Item(Key, Value)
Dict(Key) = Value
End Property
Public Sub Add(Key, Value)
Dict.Add Key, Value
End Sub
End Class
Dim d : Set d = New DictWrapper
d.Add "Beer", "Good"
Response.Write d("Beer") & "<br>"
d("Beer") = "Bad"
Response.Write d("Beer")
%>