VerifyIsInstance()

Namespace ›› System ›› MfObject ›› Methods ››
Parent Previous Next

VerifyIsInstance()

OutputVar := this.VerifyIsInstance([ClassName, LineFile, LineNumber, Source])

VerifyIsInstance([ClassName, LineFile, LineNumber, Source])

Verifies the the current object is set to an instance.

Parameters

ClassName

The name of the class Calling this is calling this method that will be passed to the MfNullReferenceException error message if not an instance.
Can be class object this or MfString instance or string var

LineFile

The LineFile to pass to the MfNullReferenceException if not an instance.
Can MfString instance or string var

LineNume

The LineNumber to pass to the MfNullReferenceException if not an instance.
Can MfString instance or string var

Source

The source to pass to the MfNullReferenceException if not an instance
Can be var or any object.

Returns

Returns true if object is an instance otherwise MfNullReferenceException instance is thrown.

Remarks

Protected method.

This method is intended to make it easier for implementers to ensure class is being called correctly in derived classes.
You can use this method to ensure instance methods are NOT called as static methods in derived classes.

Throws

Throws MfNullReferenceException if class is not an instance

Example

vme := new VerifyMethodsExample()
varA := vme.ToString() ; method succeeds.
; the following line fails and throws error instance can not call static method
varB := vme.GetValue(SomeObject)

; the following line fails and throws error method can not be called as static method
varC := VerifyMethodsExample.ToString()
varD := VerifyMethodsExample.GetValue(SomeObject) ; method succeeds.

class VerifyMethodsExample extends MfObject
{
   __New() {
       Base.__New()
       ; some other code here...
   }

   ; static method
   GetValue(obj) {
       ; throw an error if not called as a static method
       this.VerifyIsNotInstance(A_ThisFunc, A_LineFile, A_LineNumber, A_ThisFunc)
       ; more code here...
   }

   ; override base ToString method
   ToString() {
       ; throw an error if called as static method
       this.VerifyIsInstance(this, A_LineFile, A_LineNumber, A_ThisFunc)
       return "My Super Cool Class"
   }
}