[英]F# -> Access the x. from a let
As the title says, then I want to access x. 如标题所示,那么我想访问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
未定义名称空间或模块“ x”
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. ChaosPandion给出了一般性的答案,但是在您的特定情况下很可能不需要自我标识符。 Assuming
Server
is defined in Controller
or one of its base classes, you can use base.
假设
Server
是在Controller
或其基类之一中定义的,则可以使用base.
instead of a self-identifier. 而不是自我标识符。 This is described in the F# docs :
这在F#文档中进行了描述:
The keyword
base
is available in derived classes and refers to the base class instance.关键字
base
在派生类中可用,并且引用基类实例。 It is used like the self-identifier.它的使用类似于自我标识符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.