Im建立一個示例應用程序,其中我的類型層次結構不適用於在Visual Studio中進行類型排序。無論我如何嘗試安排文件(上,下),我都無法定義所有的類。F#類重新排序Visual Studio
所以他們的順序是F#中的項目
type Artist() =
let mutable artistId = 0
let mutable name = String.Empty
member x.ArtistId
with get() = artistId
and set (value) = artistId <- value
member x.Name
with get() = name
and set (value) = name <- value
type Genre() =
let mutable name = String.Empty
let mutable genreId = 0
let mutable description = String.Empty
let mutable albums = [new Album()]
member x.Name
with get() = name
and set (value) = name <- value
member x.GenreId
with get() = genreId
and set (value) = genreId <- value
member x.Description
with get() = description
and set (value) = description <- value
member x.Albums
with get() = albums
and set (value) = albums <- value
and Album() =
let mutable title = String.Empty
let mutable genre = new Genre()
let mutable albumId = 0
let mutable genreId = 0
let mutable artistId = 0
let mutable price : decimal = Decimal.Zero
let mutable albumArtUrl = String.Empty
let mutable artist = new Artist()
member x.Title
with get() = title
and set (value) = title <- value
member x.Genre
with get() = genre
and set (value) = genre <- value
member x.AlbumId
with get() = albumId
and set (value) = albumId <- value
member x.GenreId
with get() = genreId
and set (value) = genreId <- value
member x.ArtistId
with get() = artistId
and set (value) = artistId <- value
member x.Price
with get() = price
and set (value) = price <- value
member x.AlbumArtUrl
with get() = albumArtUrl
and set (value) = albumArtUrl <- value
member x.Artist
with get() = artist
and set (value) = artist <- value
因此,在上述情況下,我得到的錯誤「專輯」沒有定義。
有沒有辦法解決這個問題?或者我只需要重新考慮我的類型的整個層次結構?
所以基本上體裁類型包含列表,專輯和專輯類型包含類型的字段。是否有可能在F#中定義這種類型的層次? – netmatrix01 2012-02-06 17:53:13
靠近舒適的計算機寫一個完整的答案,但總之 - 如果你把類型放在同一個模塊/命名空間中,你可以有相互遞歸類型。只要將它們依次放置,並用關鍵字「和」替換第二個「type」關鍵字。如果你去MSDN的關於F#類型的文章,它會有一個更完整的解釋。 – 2012-02-06 18:01:05