A question about attributes.

When I define a property in my class I want to add an attribute to that property that is available to the introspection system.
For example if a property must be saved to disk on exit then I want to set an attribute called save with a value of true.

What type is the name (a string?) what type is the value (a string?)

Name is a string of course.
Value is a string (don’t forget to enclose it in double quotes) or a numeric value.

And a value is NOT required
Just having the attribute is sufficient

I think I’ve found a bug but I’m not sure…
For some reason the attribute array size is -1 although I’m pretty sure I’ve got an attribute set on a computed property.
(Thanks for that tip Norman.)

is this a bug?

Where did you set the attributes??? I don’t see any attributes assigned for your call.

I set the attributes in the IDE in the attribute editor.

Look at the get / set methods for the computed property foo in the IDE (they have a red A on the icons)

Well I don’t see any attributes on your getter or setter, but no matter because:

Dim myAttributes() As Introspection.AttributeInfo = Introspection.GetType(self).GetAttributes

This code is trying to get the attributes of the object and not the method…

From the manual.

[quote]You create attributes for an object by right+clicking on the item in the Project Editor or the Code Editor and choosing Attributes… from the contextual menu. Enter the attribute Name in the first column and optionally a Value in the second column.

The only way I can set an attribute for foo is on the getter and setter…
and the only properties I can set attributes on are computed properties.
and then only on the getter and setter.

so what have I done wrong?

In the inspector click on the gear at the top next to ID and you can set attributes for pretty much anything. (I can post a picture of what I’m talking about if you want.) The reason you can see the attribute section for computed properties without clicking on the gear is because there is no ID tab for them, they only have the gear.

Sorry I don’t know why you can not set them as described… But the ones you are setting are on the methods and not the object, so your code to retrieve them will not work.

You have to move the GetAttributes() method call into the For…Loop over the properties:

[code] Dim myProperties() as Introspection.PropertyInfo = Introspection.GetType(self).GetProperties

dim d as new Dictionary
For i as Integer=0 to Ubound(myProperties)
Dim myAttributes() As Introspection.AttributeInfo = myProperties(i).GetAttributes
For j as Integer=0 to Ubound(myAttributes)
if myAttributes(j).Name = “save” then // It’s good enough to test for the name, no need to test for the value too
// d.Value(myProperties(i).Name) = myProperties(i).Value(self)
end if
return d[/code]

Fantastic… Thank you all very much.