VerifyIsNotInstance()

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

VerifyIsNotInstance()

OutputVar := this.VerifyIsNotInstance([MethodName, LineFile, LineNumber, Source])

VerifyIsNotInstance([MethodName, LineFile, LineNumber, Source])

Verifies the the current object is NOT set to an instance.

Parameters

MethodName

The name of the calling method or property. Will be passed to the MfInvalidOperationException error message if not an instance.
Can MfString instance or string var

LineFile

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

LineNume

The LineNumber to pass to the MfInvalidOperationException if not an instance.
can be integer var

Source

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

Returns

Returns true if object is an instance otherwise MfInvalidOperationException 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 static methods are called as static method only in derived classes

Throws

Throws MfInvalidOperationException if class is 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"
   }
}