Here we will set a default value for a property of a business class, In this example we will set the default 'Priority' property in DemoTask to 'Normal' state. To do this, first we want to build DemoTask Class with 'Priority' property:
1: Public Class DemoTask
2: Inherits Task
3: ' ...
4: Private fPriority As Priority
5: Public Property Priority() As Priority
6: Get
7: Return fPriority
8: End Get
9: Set(ByVal value As Priority)
10: SetPropertyValue("Priority", fPriority, value)
11: End Set
12: End Property
13: '...
14: End Class
1: Public Enum Priority
2: Low = 0
3: Normal = 1
4: High = 2
5: End Enum
- Declaration of 'Priority' enumeration.
To initialize 'Priority' property when a DemoTask object is created, we override the AfterConstruction method as shown below:
1: Public Class DemoTask
2: Inherits Task
3: '...
4: Public Overrides Sub AfterConstruction()
5: MyBase.AfterConstruction()
6: Priority = Priority.Normal
7: End Sub
8: '...
9: End Class
This method will be executed when the new DemoTask object is created. So, the 'Priority' property will be initialized with the specified value.
[eXpressApp Framework]
[eXpressApp Framework]
No comments:
Post a Comment