(Inherits from MfCollectionBase)
Provides a way to allow for overloading methods with type checking.
Represents MfParams object.
Sealed Class.
AutoHotkey does not have any type checking built in at the time of this writing.
AutoHotkey does not allow overrides of methods such as
MyFunc(str)
MyFunc(str, int)
MyFunc(str, str)
MyFunc(str, MfChar)
The MfParams Class helps to solve that issue by giving a way to do type checking inside of the method.
Name |
Description |
|
Initializes a new instance of the MfParams class and optionally adds a range of objects to MfParams. |
Name |
Description |
|
Gets or sets a value indicating whether the MfParams instance accepts empty MfString instances. |
||
Gets or sets a value indicating whether the MfParams instance accepts empty values such as null or "" |
||
Gets or sets a value indicating whether the MfParams instance accepts only objects derived from MfObject. |
||
Gets or sets a value indicating whether the MfParams instance uses ParentEnum Type for output. |
||
Gets the number of elements contained in the MfCollectionBase instance. This property cannot be overridden. Inherited from MfCollectionBase |
||
Gets the Data Dictionary Value for extra MfParams Options |
||
Gets an MfList containing the list of elements in the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Gets or sets the element at the specified index. Inherited from MfCollectionBase |
||
Gets a value indicating whether the MfCollectionBase has a fixed size. Inherited from MfCollectionBase |
||
Gets a value indicating whether the MfCollectionBase is read-only. Inherited from MfCollectionBase |
Name |
Description |
|
Returns a new enumerator to enumerate this object's key-value pairs. This method is usually not called directly, but by the for-loop or by GetEnumerator(). Overrides MfEnumerableBase._NewEnum() Inherited from MfCollectionBase |
||
Adds an object to the end of the MfParams. |
||
Creates a new MfBool object containing value |
||
Creates a new MfChar object containing value |
||
Removes all objects from the MfCollectionBase instance. This method in not to be overridden. Inherited from MfCollectionBase |
||
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. Inherited from MfObject. |
||
Determines whether the MfCollectionBase contains a specific element. Inherited from MfCollectionBase |
||
Compares obj to current instance to see if they are the same. Inherited from MfObject. |
||
Creates a new MfFloat object containing value |
||
Gets an enumerator. Inherited from MfEnumerableBase |
||
Get the count of arguments in vardic parameter args*. |
||
Gets the Type for the for the Class .Inherited from MfObject. |
||
Gets the value of a item in the class for given index. |
||
Creates a new MfInteger object containing value |
||
Gets if current instance of object is of the same type. Inherited from MfObject. Inherited from MfObject. |
||
Searches for the specified Object and returns the zero-based index of the first occurrence within the entire MfCollectionBase. Inherited from MfCollectionBase |
||
Inserts an element into the MfCollectionBase at the specified index. Inherited from MfCollectionBase |
||
Get if the current class is an instance. Inherited from MfObject. |
||
Creates a shallow copy of the current MfObject instance. Inherited from MfObject. |
||
Performs additional custom processes when clearing the contents of the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes after clearing the contents of the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes before inserting a new element into the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes after inserting a new element into the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes when removing an element from the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes when removing an element from the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes before setting a value in the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes after setting a value in the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Performs additional custom processes when validating a value.Overrides MfCollectionBase.OnValidate() |
||
Removes the first occurrence of a specific object from the MfCollectionBase. Inherited from MfCollectionBase |
||
Removes the element at the specified index of the MfCollectionBase instance. Inherited from MfCollectionBase |
||
Creates a new MfString object containing value |
||
Gets a string representation of the Types contained in the instance of MfParams. |
||
Gets a MfGenericList of MfString of the different types in the collection. |
; Example MfParams constructor
p := new MfParams("Hello World") ; Creates new instance of Params and add String object containing "Hello World"
strObj := p.Item[0] ; strObj now contains an instance of String object
MsgBox % strObj.Value ; displays Hello World
MsgBox % p.ToString() ; Displays MfString
; Example using Primitives
intObj := new MfInteger(10)
strObj := new MfString("Hello World")
chrObj := new MfChar("%")
p := new MfParams(intObj, strObj, chrObj)
MsgBox % p.ToString() ; Displays MfInteger,MfString,MfChar
result := MyFunc(p)
/* result contains
* Integer:10
* String:Hello World
* Char:%
*/
; Example Using Add...
p := new MfParams()
p.AddInteger(10)
p.AddString("Hello World")
p.AddChar("%")
MsgBox % p.ToString() ; Displays MfInteger,MsString,MfChar
result := MyFunc(p)
/* result contains
* Integer:10
* String:Hello World
* Char:%
*/
; example passing in objects
myInt := new MfInteger(10)
myStr := new MfString("Hello World")
myChar := new MfChar("%")
result := MyFunc(myInt, myStr, myChar)
/* result contains
* Integer:10
* String:Hello World
* Char:%
*/
; Example using Data
; this example passes MfParams into MfInteger.Parse method with
; Data Key of ReturnAsObject. This cause MfInteger.Parse to return is value
; as an instance of MfInteger rather then the default of a var containing integer.
pStr := "33"
Parms := new MfParams()
Parms.AddString(pStr)
Parms.Data.Add("ReturnAsObject", true)
; parse will return an instance of MfInteger rather than a var integer
; because Parms.Data.Add("ReturnAsObject", true)
int := MfInteger.Parse(Parms)
MsgBox % int.Value
; Also the results of our MyFunc will return an object of MfString
; because Parms.Data.Add("ReturnAsObject", true)
result := MyFunc(Parms)
MsgBox % result.Value ; displays 33
; Example constructor using MfParams static Primitive generators
; Create a new instance of MfParams
; add Integer, String, Char in the constructor
p := new MfParams(MfParams.I(10), MfParams.S("Hello World"), MfParams.C("%"))
MsgBox % p.ToString() ; Displays: MfInteger,MfString,MfChar
result := MyFunc(p)
/* result contains
* Integer:10
* String:Hello World
* Char:%
*/
; Example AddRange using MfParams static Primitive generators
p := new MfParams() ; create a new instance of MfParams
p.AddRange(MfParams.I(10), MfParams.S("Hello World"), MfParams.C("%"))
MsgBox % p.ToString() ; Displays MfInteger,MfString,MfChar
result := MyFunc(p)
/* result contains
* Integer:10
* String:Hello World
* Char:%
*/
ExitApp
; Example function
MyFunc(args*) {
; check to see if the first arg is in instance of MfPrams and use if it is
; args is 1 base index
if (MfObject.IsObjInstance(args[1], MfParams))
{
p := args[1] ; arg 1 is a MfParams object so we will use it
} else {
; Mfparams was not passed in so we will create an instance and add all the args
p := new MfParams()
for index, arg in args
{
p.Add(arg)
}
}
; this method only takes 1 to 3 arguments so we will check and throw an error if wrong number of args
if ((p.Count < 1) || (p.Count > 3)) {
e := new MfNotSupportedException(MfEnvironment.Instance.GetResourceString("NotSupportedException_MethodOverload"))
e.SetProp(A_LineFile, A_LineFile, A_ThisFunc)
throw e
}
strParams := p.ToString()
retval := "unknown"
if (strParams = "MfString") {
str := p.GetValue(0) ; get the first item in the params
retval := str
} else if (strParams = "MfString,MfInteger") {
str := p.GetValue(0) ; get the first item in the params
int := p.GetValue(1) ; get the second item in the params
retval := "String:" . str . " Integer:" . int
} else if (strParams = "MfString,MfString") {
strObjA := p.Item[0] ; get the first object which is a String Object
strObjA := p.Item[1] ; get the second object which is a String Object
retval := MfString.Format("StringA:{0}`nStringB:{1}", strObjA.Value, strObjB.Value)
} else if (strParams = "MfString,MfChar") {
str := p.GetValue(0) ; get the first item in the params
strCh := p.GetValue(1) ; get the second item in the params
retval := MfString.Format("String:{0}`nChar:{1}", str, strCh)
} else if (strParams = "MfInteger,MfString,MfChar") {
retval := MfString.Format("Integer:{0}`nString:{1}`nChar:{2}", p.Item[0].Value, p.Item[1].Value, p.Item[2].Value)
}
; optionally return different value using Data Property
if (p.Data.Contains("ReturnAsObject") && (p.Data.Item["ReturnAsObject"] = true)) {
return new MfString(retval) ; return a new instance of MfString
} else {
return retval
}
}