2013-12-13 71 views
3

我正在使用一個類型提供程序來創建一個版本化的api,在那裏你可以選擇選擇比當前最新版本更老的組件調用版本。我可以在F#類型提供程序中創建多個相同類型的別名嗎?

Provided.ComponentName.VersionName(... this is the type constructor ...) 

ComponentName是目前命名空間,如果有差別:

目前,它在一個命名空間,看起來像把這些。

一旦我已經建立了組件的所有特定版本,我也想揭露:

Provided.ComponentName.Latest(... constructor ...) 

爲一個靜態方法或類型別名,將返回最近的一個實例版。

這樣做的最好方法是什麼?

回答

3

我不認爲有辦法生成F#類型的別名(這將是一個很好的方式別名Latest到特定版本的類型)。

作爲替代,我想你可以生成VersionName作爲嵌套類型,並將Latest作爲返回適當版本的類型的靜態方法。要做到這一點,ComponentName必須是包含其它類型的一種類型&一個靜態方法:

// Creates an instance of `VersionName` 
// (a nested type of `ComponentName`) 
Provided.ComponentName.VersionName(....) 

// Creates an instance of `SomeVersionName` type 
// (a static method of the `ComponentName` type) 
Provided.ComponentName.Latest(....) 

這個唯一的醜陋的東西是VersionName是一種類型(並可以使用new創建),而Latest是靜態方法,所以它不會與new一起使用。

+0

感謝Tomas。可惜別名是不可能的。 – mavnn

相關問題