简体   繁体   中英

How can I create ASP class with “To” property (like CDONTS.NewMail)?

The CDONTS.NewMail class let's me send email like this:

Set MailObj = Server.CreateObject("CDONTS.NewMail")
MailObj.To = someone@example.com
' set other properties of MailObj
MailObj.Send

I can create my own class in ASP, but it won't let me define a property named "To".

Is there some way I can create a class with a property named "To" in a class that I define?

class MyMail
  Public To          ' this doesn't work!
  Public From        ' this works great!
end class

It should be possible to mark the identifier with []. As in:

Option Explicit

Class cC
  Public [To]
End Class

Dim oC : Set oC = New cC
oC.To = 4711
Dim i
For i = 0 To 1
    WScript.Echo oC.To
Next

output:

cscript 36585334.vbs
4711
4711

(See here and here for 'escaped names'/[] in another Basic dialect.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM