Class MacroMethodContainer
- Namespace
- CMS.MacroEngine
- Assembly
- CMS.MacroEngine.dll
Container for method extensions of an arbitrary object used by MacroEngine.
public class MacroMethodContainer : MacroExtensionContainer<MacroMethodContainer, MacroMethod>
- Inheritance
-
objectMacroMethodContainer
- Inherited Members
- Extension Methods
Constructors
MacroMethodContainer()
public MacroMethodContainer()
Properties
RegisteredMethods
Returns enumerable of all methods.
public IEnumerable<MacroMethod> RegisteredMethods { get; }
Property Value
- IEnumerable<MacroMethod>
Methods
CompareDateTime(DateTime, DateTime, string)
Compares DateTime values.
protected static object CompareDateTime(DateTime date1, DateTime date2, string op)
Parameters
date1DateTimeDateTime to compare
date2DateTimeDateTime to compare
opstringComparison operator
Returns
- object
CompareDouble(double, double, string)
Compares double numbers.
protected static object CompareDouble(double number1, double number2, string op)
Parameters
number1doubleNumber to compare
number2doubleNumber to compare
opstringComparison operator
Returns
- object
CompareString(string, string, string, EvaluationContext)
Compares strings (lexicographically).
protected static object CompareString(string str1, string str2, string op, EvaluationContext context)
Parameters
str1stringString to compare
str2stringString to compare
opstringComparison operator
contextEvaluationContextEvaluation context
Returns
- object
CompareTimeSpan(TimeSpan, TimeSpan, string)
Compares TimeSpan values.
protected static object CompareTimeSpan(TimeSpan span1, TimeSpan span2, string op)
Parameters
span1TimeSpanTimeSpan to compare
span2TimeSpanTimeSpan to compare
opstringComparison operator
Returns
- object
CompareValues(EvaluationContext, string, params object[])
Returns true if first parameter is lower than or equal to second.
protected static object CompareValues(EvaluationContext context, string op, params object[] parametersToCompare)
Parameters
contextEvaluationContextEvaluation context with child resolver
opstringOperator
parametersToCompareobject[]First two parameters are numbers to compare
Returns
- object
GetBoolParam(object)
Returns the parameter converted to boolean or false if parameter is not boolean.
protected static bool GetBoolParam(object parameter)
Parameters
parameterobjectParameter to convert
Returns
- bool
GetDecimalParam(object, string)
Returns the parameter converted to decimal or zero if parameter is not decimal.
protected static decimal GetDecimalParam(object parameter, string culture = null)
Parameters
parameterobjectParameter to convert
culturestringCulture to use to convert object to double
Returns
- decimal
GetDoubleParam(object, string)
Returns the parameter converted to double or zero if parameter is not double.
protected static double GetDoubleParam(object parameter, string culture = null)
Parameters
parameterobjectParameter to convert
culturestringCulture to use to convert object to double
Returns
- double
GetGuidParam(object)
Converts the parameter to GUID. Returns Guid.Empty if parameter is not GUID.
protected static Guid GetGuidParam(object parameter)
Parameters
parameterobjectParameter to convert
Returns
- Guid
GetIntParam(object)
Returns the parameter converted to integer or zero if parameter is not integer.
protected static int GetIntParam(object parameter)
Parameters
parameterobjectParameter to convert
Returns
- int
GetLazyParamValue(object, EvaluationContext, out bool)
Gets the lazy parameter value by evaluating it
protected static object GetLazyParamValue(object parameter, EvaluationContext evalContext, out bool securityPassed)
Parameters
parameterobjectParameter to evaluate
evalContextEvaluationContextEvaluation context
securityPassedboolIndicates whether the security check passed
Returns
- object
GetMethod(string)
Returns a method of given name (return null if specified method does not exist).
public MacroMethod GetMethod(string name)
Parameters
namestringMethod name
Returns
GetMethodForObject(object, string)
Returns macro method object of given name if registered for specified object. It loops through all MacroMethodContainer extensions of given object type. Returns null if there is no such Extension for given object.
public static MacroMethod GetMethodForObject(object obj, string name)
Parameters
objobjectObject to check
namestringName of the method
Returns
GetMethodsForObject(object)
Returns list of macro method extension registered for specified object. Returns null if there is no such extension for given object.
public static IEnumerable<MacroMethod> GetMethodsForObject(object obj)
Parameters
objobjectObject to check
Returns
- IEnumerable<MacroMethod>
GetOptionalParam<T>(object[], int, T, CultureInfo)
Gets the optional param of the given type
protected static T GetOptionalParam<T>(object[] parameters, int index, T defaultValue, CultureInfo culture = null)
Parameters
parametersobject[]List of method parameters
indexintParameter index
defaultValueTDefault value in case conversion fails or parameter is not available
cultureCultureInfoCulture for the conversion
Returns
- T
Type Parameters
T
GetParamValue<T>(object[], int, T)
Returns the index-th parameter evaluated using given resolver.
protected static T GetParamValue<T>(object[] parameters, int index, T defaultValue)
Parameters
parametersobject[]Method parameters
indexintIndex of the parameter within the array
defaultValueTDefault value which will be used if the parameter is not present
Returns
- T
Type Parameters
T
GetStringParam(object, string)
Returns the parameter converted to string or empty string.
protected static string GetStringParam(object parameter, string culture = null)
Parameters
parameterobjectParameter to convert
culturestringCulture to use to convert object to string
Returns
- string
RegisterExtensions()
Registers all the methods.
protected override void RegisterExtensions()
RegisterMethod(MacroMethod)
Registers the given method.
public void RegisterMethod(MacroMethod method)
Parameters
methodMacroMethodMethod to register
RegisterMethodInternal(string, Func<EvaluationContext, object[], object>, Type, string, int, object[,], string[])
Registers the given method within the method table.
protected void RegisterMethodInternal(string name, Func<EvaluationContext, object[], object> method, Type type, string comment, int minimumParameters, object[,] parameterDefinition, string[] specialParameters = null)
Parameters
namestringMethod name
methodFunc<EvaluationContext, object[], object>Method delegate
typeTypeReturn type of the method
commentstringComment for the method
minimumParametersintMinimal number of parameters needed to call the method
parameterDefinitionobject[,]Parameter definition in format {{name, type, comment}, {name, type, comment}}
specialParametersstring[]A list of special parameters needed to be supplied by resolver
RegisterMethodInternal(string[], Func<EvaluationContext, object[], object>, Type, string, int, object[,], string[])
Registers the given method within the method table.
protected void RegisterMethodInternal(string[] names, Func<EvaluationContext, object[], object> method, Type type, string comment, int minimumParameters, object[,] parameterDefinition, string[] specialParameters = null)
Parameters
namesstring[]Method names to register
methodFunc<EvaluationContext, object[], object>Method delegate
typeTypeReturn type of the method
commentstringComment for the method
minimumParametersintMinimal number of parameters needed to call the method
parameterDefinitionobject[,]Parameter definition in format {{name, type, comment}, {name, type, comment}}
specialParametersstring[]A list of special parameters needed to be supplied by resolver
RegisterMethods()
Registers all the methods.
protected virtual void RegisterMethods()
RegisterMethods(params MacroMethod[])
Registers the given methods.
public void RegisterMethods(params MacroMethod[] methods)
Parameters
methodsMacroMethod[]Methods to register
UnwrapContainer(object[])
Unwraps all DateTime and TimeSpan containers to their original system value.
protected static object[] UnwrapContainer(object[] parameters)
Parameters
parametersobject[]Parameters to process
Returns
- object[]