OutputVar := instance.Is(type)
Gets if current instance of object is of the same type
type
The object to compare this instance type with Type can be an instance of MfType or an object derived from MfObject or an instance of or a string containing the name of the object type such as "MfObject"
Returns true if current object instance is of the same type as the type Parameter otherwise false
If a string is used as the Type case is ignored so "MfObject" is the same as "mfobject"
IsNotObjectInstance(), IsObjectInstance(), IsInstance(), IsMfObject()
; Is checking examples
MyBar := new Bar("Hello World", "have a nice day!")
MyFoo := new Foo("Hello World")
MySubFoo := new Foo.SubFoo(true)
MsgBox % MyBar.Is(Foo) ; displays 1 for true as Bar inherits foo
MsgBox % MyBar.Is(MfObject) ; displays 1 for true as Bar inherits foo and foo inherits MfObject
MsgBox % MyFoo.Is(MfObject) ; displays 1 for true as foo inherits MfObject
MsgBox % MyFoo.Is(Bar) ; displays 0 for false as foo does not inherit from bar
MsgBox % MyBar.Is(MyFoo.GetType()) ; displays 1 for true
MsgBox % MySubFoo.Is("MfObject") ; displays 1 for true
MsgBox % MySubFoo.Is(Foo.SubFoo) ; displays 1 for true
MsgBox % MyFoo.Is(MySubFoo.GetType()) ; displays 0 for false
ExitApp
; Create a classes that derives from MfObject
class Foo extends MfObject
{
m_FooMsg := ""
__New(msg) {
base.__New()
this.m_FooMsg := msg
}
GetFoo() {
if (this.IsInstance()) { ; check to see if class is actual instance
return this.m_FooMsg
}
return "Error: Not an instance"
}
class SubFoo extends MfObject
{
__New(value) {
base.__New()
try {
this.m_stuff := MfBool.GetValue(value)
} catch e {
ex := new MfInvalidCastException(MfEnvironment.Instance.GetResourceString("InvalidCastException_ValueToBoolean"), e)
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
m_stuff := Null
IsStuff[]
{
get {
return this.m_stuff
}
set {
ex := new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_readonly_Property"))
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
}
}
class Bar extends Foo
{
m_BarMsg := ""
__New(msgFoo, msgBar) {
base.__New(msgFoo)
this.m_BarMsg := msgBar
}
GetFooBar() {
if (this.IsInstance()) { ; check to see if class is actual instance
str := this.GetFoo() . ", " . this.m_BarMsg
return str
}
return "Error: Not an instance"
}
class SubBar extends MfObject
{
m_barStuff := false
IsBarStuff[]
{
get {
return this.m_barStuff
}
set {
try {
this.m_barStuff := MfBool.GetValue(value)
} catch e {
ex := new MfInvalidCastException(MfEnvironment.Instance.GetResourceString("InvalidCastException_ValueToBoolean"), e)
ex.SetProp(A_LineFile, A_LineNumber, A_ThisFunc)
throw ex
}
}
}
}
}