(Inherits from MfSingletonBase)
Represents the base class for custom attributes.
Abstract class
Properties, Methods, Remarks, Related, Example
Name |
Description |
|
Constructor for Abstract MfAttribute Class |
Name |
Description |
|
Gets a Singleton instance of derived class. Inherited from MfSingletonBase |
||
Get The TypeCode of the current instance as var string |
Name |
Description |
|
Adds MfAttribute extended items to extended classes. Inherited from MfObject. |
||
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. Overrides MfObject.CompareTo() |
||
Set current Instance of derived class to null. Inherited from MfSingletonBase |
||
Compares obj to current instance to see if they are the same. Inherited from MfObject. |
||
Gets an MfAttribute of the class. Inherited from MfObject. |
||
Gets a MfGenericList of MfAttribute that Contains the attributes for the current class instance. Inherited from MfObject. |
||
Gets A hash code for the current MfObject. Inherited from MfObject. |
||
Protected Abstract method. Gets the instance of the Singleton. Inherited from MfSingletonBase |
||
Gets the zero-based index value of the position of MfAttribute within the instance of the class. Inherited from MfObject. |
||
Gets the Type for the for the Class .Inherited from MfObject. |
||
Gets if the current instance of class derived from MfSystemException has MfAttribute. Inherited from MfObject. |
||
Gets if current instance of object is of the same type. Inherited from MfObject. Inherited from MfObject. |
||
Get if the current class is an instance. Inherited from MfObject. |
||
Creates a shallow copy of the current MfObject instance. Inherited from MfObject. |
||
Gets a string representation of the MfObject. Inherited from MfObject. |
||
Verifies the the current object is set to an instance. Inherited from MfObject. |
||
VerifyIsNotInstance([MethodName, LineFile, LineNumber, Source]) |
Verifies the the current object is NOT set to an instance. Used in Static methods. Inherited from MfObject. |
MfAttribute adopted a singleton pattern. Using the Singleton allows for one instance of an attribute to be added to many classes thus saving resources. If Required in derived classes new instance can still be created by calling the new Constructor method.
Custom Attributes can be added to a class by Calling AddAttribute() method.
MfObject, MfFlagsAttribute, MfSingletonBase
#NoEnv
#SingleInstance Force
#NoTrayIcon
#KeyHistory 0
SetBatchLines -1
ListLines, Off
SendMode Input ; Forces Send and SendRaw to use SendInput buffering for speed.
SetTitleMatchMode, 3 ; A window's title must exactly match WinTitle to be a match.
SetWorkingDir, %A_ScriptDir%
; Include Mini-Framework 0.4.0.5
#Include <inc_mf_0_4>
ItmLst := new MyItemList()
i := 0
Try
{
While, i < 100
{
ran := Mfunc.Random(1, 100)
if (Mod(ran, 2)) ; odd numbers
{
itm := new MyItem(A_TickCount)
ItmLst.Add(itm)
}
else
{
itm := new MyItemCustom(A_TickCount)
ItmLst.Add(itm)
}
i++
sleep, 5
}
}
Catch e
{
MsgBox, 16, Error, % e.Message
}
MsgBox, 64, Custom Items, % "Custom Item Count: " . ItmLst.CountCustom
MsgBox, 64, Total Items, % "Total Item Count: " . ItmLst.Count
; Now we will remove the first item in the list that has a custom attribute
iFirstCustom := -1
For i, Item in ItmLst
{
if (Item.HasAttribute(CustomAttribute))
{
iFirstCustom := i
break
}
}
if (iFirstCustom > -1)
{
ItmLst.RemoveAt(iFirstCustom)
MsgBox, 64, Custom Items, % "Custom Item Count: " . ItmLst.CountCustom
MsgBox, 64, Total Items, % "Total Item Count: " . ItmLst.Count
}
ExitApp
; Create a base Class
class MyItemBase extends MfObject
{
__New(ID) {
if (this.__Class = "MyItemBase") {
throw new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_AbstractClass"
, "MyItemBase"))
}
base.__New()
this.m_isInherited := True
If (MfNull.IsNull(ID))
{
ex := new MfArgumentNullException("ID")
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
Throw ex
}
Try
{
this.m_ItemID := MfInt64.GetValue(ID)
}
Catch e
{
ex := new MfArgumentException(MfEnvironment.Instance.GetResourceString("Arg_InvalidCastException"), e)
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
Throw ex
}
}
m_ItemID := Null
ItemID[]
{
get {
return this.m_ItemID
}
set {
this.m_ItemID := MfInt64.GetValue(value)
return this.m_ItemID
}
}
}
; Represents a General Item
class MyItem extends MyItemBase
{
__New(ID) {
base.__New(ID)
this.m_isInherited := this.__Class != "MyItem"
}
}
; Represents a Custom Item with Custom Attribute
class MyItemCustom extends MyItemBase
{
__New(ID) {
base.__New(ID)
this.m_isInherited := this.__Class != "MyItemCustom"
; Add Custom Attribute Instance
this.AddAttribute(CustomAttribute.Instance)
}
}
; List Class that only accepts classes derived from MyItemBase
class MyItemList extends MfGenericList
{
__New(ID) {
base.__New(MyItemBase)
this.m_isInherited := this.__Class != "MyItemList"
}
; overrides MfGenericList Add
Add(obj) {
base.Add(obj)
if (obj.HasAttribute(CustomAttribute))
{
this.m_CountCustom ++
}
}
; overrides MfGenericList Remove
Remove(obj) {
RemovedItem := base.Remove(obj)
if ((MfNull.IsNull(RemovedItem) = false) && (RemovedItem.HasAttribute(CustomAttribute)))
{
this.m_CountCustom --
}
}
; overrides MfGenericList RemoveAt
RemoveAt(index) {
RemovedItem := base.RemoveAt(index)
if ((MfNull.IsNull(RemovedItem) = false) && (RemovedItem.HasAttribute(CustomAttribute)))
{
this.m_CountCustom --
}
}
m_CountCustom := 0
; property that represents Items in list with CustomAttriube
CountCustom[]
{
get {
return this.m_CountCustom
}
set {
ex := new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_readonly_Property"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
Throw ex
}
}
}
class CustomAttribute extends MfAttribute
{
static _instance := "" ; Static var to contain the singleton instance
__New() {
base.__New()
this.m_isInherited := this.__Class != "CustomAttribute"
}
; Overrides MfSingletonBase
DestroyInstance() {
CustomAttribute._instance := Null ; Clears current instance and releases memory
}
; Overrides MfSingletonBase
GetInstance() {
if (MfNull.IsNull(CustomAttribute._instance)) {
CustomAttribute._instance := new CustomAttribute()
}
return CustomAttribute._instance
}
}