As the title says, then I want to access x. from a let instead of a member.
The following works:
type UploadController() =
inherit Controller()
member x.UploadPath
with get() = x.Server.MapPath "~/Uploads"
But this:
type UploadController() =
inherit Controller()
let uploadPath = x.Server.MapPath "~/Uploads"
Throws a compiler error:
The namespace or module 'x' is not defined
Mission impossible?
You can define a reference like this:
type UploadController () as x =
inherit Controller ()
let uploadPath = x.Server.MapPath "~/Uploads"
ChaosPandion has given the general answer, but it's probable that you don't need a self-identifier in your specific case. Assuming Server
is defined in Controller
or one of its base classes, you can use base.
instead of a self-identifier. This is described in the F# docs :
The keyword
base
is available in derived classes and refers to the base class instance. It is used like the self-identifier.
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.