While properties may look like commands and functions, they aren't. A property shouldn't be used unless directly backed by a member. So if a string property call MyStringProperty
is present, you should have a string member called MyString
in the same scope. The exception is properties that have only a get accessor. They might be used to compute something. However, all get accessors are implicitly constant as though they were declared with the const keyword.
Properties in ASIL are most similar to those in C#, but are more flexible. Think of the get clause as a function and the set clause as a command. Each clause is a type of procedure called an "accessor".
A simple property:
public property String MyProperty get return "a" set someMember = value
Note: Unlike functions, a property can be called either the get or the set accessor, but not both in a single call. In the code below, ASIL would call the set accessor , but not the get accessor. Instead, ASIL would pass the string constant to whatever S$
turned out to be.
S$ = MyProperty = "5sdf"
A property can be virtual and shown below. If you're overriding such a property, you need to use the override keyword.
public virtual property IntProperty% get return 3 set intMember% = value
The get and set accessors can have different access qualifiers. You can also make one final and one virtual if needed. Whatever is given for the property applies for the accessors unless they override it.
public property NewProp# virtual get return null final set test# = value
Unlike C#, ASIL properties can be indexed and take parameters. These parameters are calleed "index parameters". Your property must take the same index parameters for both the get and set accessors. If you need different versions, consider overloading. If the type you're returning has the self property, your property takes precedence. Custom keywords are allowed. The brackets are required. Those in the declaration below don't mark an optional sequence, but are how you specify the property is indexed.
public property boolean IsReady[var int index] get return i[index] set i[index] = value
You call an indexed property like this:
if IsReady[4] then IsReady[3] = true
You can have a property on the self keyword. This is called a default property. It is always indexed.
public property byte self[var String strName] get return map.lookupName strName
This is how you call it:
instance["name"]
See [Delegates] on how to create delegates for properties.
Examine the code below.
class MyClass public property int self[var int index] get ' return some value class OtherClass public property MyClass Prop[var int index] get ' return some value
Now look at this code:
var OtherClass myOtherClass = new OtherClass ' Presumably we declared constructors for both classes var int i% = myOtherClass.Prop[7] ' Error as OtherClass.Prop returns a MyClass var int j% = myOtherClass.Prop[7][4] ' Valid as the "[4]" portion is the default property
ASIL allows properties to be overloaded. However, all the overloads must be of the same type. You will need at least one to be indexed, unless the property is the default property, in which case all the overloads will be indexed.
Wiki: Delegates
Wiki: Home
Wiki: When is it a procedure, command, function, property, property accessor, method, complex statement, or type cast?
Wiki: keywords-property
Wiki: keywords-throws
Wiki: operators-brackets