Equals()

Namespace ›› System ›› MfEnum ›› Methods ››
Parent Previous Next

Equals()

Overrides MfObject.Equals

OutputVar := MfEnum.Equals(objA, ObjB)
OutputVar := instance.Equals(objA)

Equals(objA)

Compares objA against current MfEnum instance to see if they have the same Value.

MfEnum.Equals(objA, objB)

Compares objA against objB to see if they have the same value.

Static Method

Parameters

objA

The first MfEnum.EnumItem or MfEnum derived instance to compare.

objB

The second MfEnum.EnumItem or MfEnum derived instance to compare.

Returns

Returns var containing Boolean value of true if the MfEnum.EnumItem.Value or MfEnum.Value instances have the samve Value otherwise false.

Throws

Throws MfArgumentNullException if objA is null.
Throws MfNullReferenceException if Non-Static [Equals(objA)] method is called when insance as not be created
Throws MfArgumentException if objA or objB are not type of MfEnum.EnumItem or MfEnum.

Related

MfEnum.EnumItem.Equals()
MfEnum.CompareTo()


Example

; create a new Enum Item and assign the value of KeysRegDword
myRegOp := new RegOptEnum(RegOptEnum.Instance.KeysRegDword)

; read value from ini file
mykey := Mfunc.IniRead("C:\Temp\myfile.ini", "REG", "KEYS_REG_DWORD")
; mykey is expected to contain value of KeysRegDword

; set var initial value to null
outEnumItem := MfNull.Null

; wrap in try block as ParseItem can throw MfException
try
{
   outEnumItem := RegOptEnum.Instance.ParseItem(myKey)
}
catch e
{
   MsgBox, 16, Error, % "There was an error Parsing Item: " . e.Message
   Exit, 1
}

; could also be written as: if (RegOptEnum.Instance.KeysRegDword.Value = outEnumItem.Value) {
; as show below
if (myRegOp.Equals(outEnumItem)) {
   MsgBox, 64, Found Default, The Default was found.
}

; same as above could be written as: if (RegOptEnum.Instance.KeysRegDword.Equals(outEnumItem)) {
; as shown above
if (myRegOp.Value = outEnumItem.Value) {
   MsgBox, 64, Found Default, The Default was found.
}

; display a message if not equal to KeysRegDword
if (myRegOp.Value != outEnumItem.Value) {
   MsgBox, 64, Non-Standard, % "Found no standard value: " outEnumItem.Name
}

ExitApp


In the example above a new instance of RegOptEnum was created. This is fine but note that creating a new instance of the MfEnum Derived class does make a copy of the entire class in memory. A more efficient way is to use the Instance Property of the current enumeration to test against EnumItems. the same code above can be written in the same way without creating new instances of the RegOptEnum. Below is the same procedure written in a differrent way by using the EnumItem.Equals of the Parent Enum.

; read value from ini file
mykey := Mfunc.IniRead("C:\Temp\myfile.ini", "REG", "KEYS_REG_DWORD")
; mykey is expected to contain value of KeysRegDword

; set var initial value to null
outEnumItem := Null

; wrap in try block as ParseItem can throw MfException
try
{
   outEnumItem := MfEnum.ParseItem(RegOptEnum.GetType(), myKey)
}
catch e
{
   MsgBox, 16, Error, % "There was an error Parsing Item: " . e.Message
   Exit, 1
}

; could also be written as: if (RegOptEnum.Instance.KeysRegDword.Value = outEnumItem.Value) {
; as show below
if (RegOptEnum.Instance.KeysRegDword.Equals(outEnumItem)) {
   MsgBox, 64, Found Defaut, The Default was found.
}

; same as above could be written as: if (RegOptEnum.Instance.KeysRegDword.Equals(outEnumItem)) {
; as shown above
if (RegOptEnum.Instance.KeysRegDword.Value = outEnumItem.Value) {
   MsgBox, 64, Found Defaut, The Default was found.
}

; display a message if not equal to KeysRegDword
if (RegOptEnum.Instance.KeysRegDword.Value != outEnumItem.Value) {
   MsgBox, 64, Non-Standard, % "Found no standard value: " . outEnumItem.Name
}

ExitApp

; create a new enumeration class by inheriting/extending the MfEnum
class RegOptEnum extends MfEnum
{
   static m_Instance := MfNull.Null
   __New(args*)
   {
       if (this.base.__Class != "RegOptEnum")
       {
           throw new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_Sealed_Class"
               ,"RegOptEnum"))
       }
       base.__New(args*)
       ; set MfObject m_isInherited flag for testing if Class is inherited/extended if needed
       ; This could be set to false as this class cannot be inherited/extended as set in this constructor above
       ; but will do it the standard way.
       this.m_isInherited := this.__Class != "RegOptEnum"
   }
       
   ; override the base AddEnums, this is required
   ; add all the enum values for your enum here
   AddEnums() {
       this.AddEnumValue("RegDword", 0)
       this.AddEnumValue("KeysRegDword", 1)
       this.AddEnumValue("RegSz", 2)
       this.AddEnumValue("KeysRegSz", 3)
       this.AddEnumValue("RegBinary", 4)
       this.AddEnumValue("KeysRegBinary", 5)
       this.AddEnumValue("AutoresponseRegSz", 6)
       this.AddEnumValue("KeysAutoresponseRegSz", 7)
       this.AddEnumValue("AutoupdateRegSz", 8)
       this.AddEnumValue("KeysAutoupdateRegSz", 9)
       this.AddEnumValue("AutoupdateRegBinary", 10)
       this.AddEnumValue("KeysAutoupdateRegBinary", 11)
       this.AddEnumValue("KeypathsRegSz", 12)
       this.AddEnumValue("KeysKeypathsRegSz", 13)
       this.AddEnumValue("KeypathsRegDword", 14)
       this.AddEnumValue("KeysKeypathsRegDword", 15)
       this.AddEnumValue("WindowplacementRegBinary", 16)
       this.AddEnumValue("KeysWindowplacementRegBinary", 17)
   }

   ; override the base DestroyInstance, this is required
   DestroyInstance() {
       RegOptEnum.m_Instance := Null        
   }

   ; override the base GetInstance, this is required
   ; Get a static default instance, create if not exist yet
   GetInstance() {
       if (MfNull.IsNull(RegOptEnum.m_Instance))
       {
           RegOptEnum.m_Instance := new RegOptEnum(0)
       }
       return RegOptEnum.m_Instance
   }
}