How to access attributes from subtypes

83 views Asked by At

I followed the TSL documentation on attributes and created two classes:

[GraphNode]
cell struct Fruit
{
    string color;
}

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

I used the generated code like this:

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

The code can access the variety field, but cannot access the color field:

'Apple' does not contain a definition for 'color' and no extension method 'color' accepting a first argument of type 'Apple' could be found (are you missing a using directive or an assembly reference?)

How can I access the inherited attribute?

1

There are 1 answers

3
Andreas Hassmann On BEST ANSWER

Those attributes do not have an intrinsic meaning apart from the meaning you attach to them. "BaseType" does not make Apple derive from Fruit. You can just ask in your code for the value of the attribute "BaseType" on your cell.