2017-03-06 29 views
0

如何訪問屬性,我也跟着TSL documentation on attributes並創建了兩個類:從亞型

[GraphNode] 
cell struct Fruit 
{ 
    string color; 
} 

[GraphNode, BaseType : Fruit] 
cell struct Apple 
{ 
    string variety; 
} 

我用這樣生成的代碼:

Apple apple = new Apple(); 
Console.WriteLine(apple.variety); 
Console.WriteLine(apple.color); 

的代碼可以訪問variety場,但不能訪問color字段:

'Apple'不包含'co lor'並且沒有可以找到接受'Apple'類型的第一個參數的擴展方法'color'(您是否缺少使用指令或程序集引用?)

如何訪問繼承屬性?

回答

0

除了附加到它們的含義之外,這些屬性沒有內在含義。 「BaseType」不會讓Apple從Fruit中派生出來。您可以在代碼中詢問您的單元格屬性「BaseType」的值。

+0

是否有任何方法可以正確地爲一個單元格子類型,或者我應該將所需的屬性(例如'string')複製到每個子類? –

+0

這是我與你分享的一個願望。但據我所知,你不能繼承。我也是用拷貝來做的。 –