[<Extension>]
static member ToOrganizationRequest<'T when 'T :> OrganizationRequest> (entity: Entity) =
let request = Activator.CreateInstance(typeof<'T>) :?> OrganizationRequest
request.Parameters.Item "Target" <- entity
request
[<Extension>]
static member ToOrganizationRequest<'T when 'T :> OrganizationRequest> (entities: seq<Entity>) =
entities
|> Seq.map (fun x -> x.ToOrganizationRequest<'T>())
第二extensionmethod不能引用該第一,所以F#的一種擴展方法,參考另一
|> Seq.map(樂趣X - > x.ToOrganizationRequest <「T>())
失敗,因爲我不能使用ToOrganizationRequest。 有什麼辦法讓它理解參考?
靜態成員可以通過'TypeName.StaticMember'獲得,所以嘗試使用它來代替'this.StaticMember'。 –
你是什麼意思?我應該能夠做一些像Entity.ToOrganizationRequest <'T>?因爲我無法做到這一點。 –