/// <summary> /// Defines a required parameter using the details specified /// </summary> /// <param name="name">The name</param> /// <param name="description">The description</param> /// <param name="dataType">The data type</param> /// <param name="defaultValue">The default value (optional)</param> protected virtual void DefineRequiredParameter ( string name, string description, Type dataType, object defaultValue = null ) { Validate.IsNotEmpty(name); Validate.IsNotNull(dataType); var optionalParameters = GetOptionalParameters(); // Ensure no optional parameters have been defined if (optionalParameters.Any()) { throw new InvalidOperationException ( "Required parameters must be defined before optional parameters." ); } var configuration = new FunctionParameterConfiguration() { Name = name, Description = description, DataType = dataType, DefaultValue = defaultValue, Optional = false }; DefineParameter(configuration); }
/// <summary> /// Defines a parameter for the function /// </summary> /// <param name="configuration">The parameter configuration</param> protected virtual void DefineParameter ( FunctionParameterConfiguration configuration ) { Validate.IsNotNull(configuration); Validate.IsNotEmpty(configuration.Name); Validate.IsNotNull(configuration.DataType); if (this.Parameters == null) { this.Parameters = new List <FunctionParameter>(); } var matchFound = this.Parameters.Any ( m => m.Name.Equals(configuration.Name, StringComparison.OrdinalIgnoreCase) ); if (matchFound) { throw new InvalidOperationException ( $"The parameter '{configuration.Name}' has already been defined." ); } var parameter = new FunctionParameter ( this, configuration ); this.Parameters.Add(parameter); }
/// <summary> /// Constructs the function parameter with dependencies /// </summary> /// <param name="function">The function</param> /// <param name="configuration">The configuration details</param> public FunctionParameter ( IFunction function, FunctionParameterConfiguration configuration ) { Validate.IsNotNull(function); Validate.IsNotNull(configuration); this.Function = function; Configure(configuration); }
/// <summary> /// Defines an optional parameter using the details specified /// </summary> /// <param name="name">The name</param> /// <param name="description">The description</param> /// <param name="dataType">The data type</param> /// <param name="defaultValue">The default value (optional)</param> protected virtual void DefineOptionalParameter ( string name, string description, Type dataType, object defaultValue = null ) { Validate.IsNotEmpty(name); Validate.IsNotNull(dataType); var configuration = new FunctionParameterConfiguration() { Name = name, Description = description, DataType = dataType, DefaultValue = defaultValue, Optional = true }; DefineParameter(configuration); }
/// <summary> /// Defines a parameter for the function /// </summary> /// <param name="configuration">The parameter configuration</param> protected virtual void DefineParameter ( FunctionParameterConfiguration configuration ) { Validate.IsNotNull(configuration); Validate.IsNotEmpty(configuration.Name); Validate.IsNotNull(configuration.DataType); if (this.Parameters == null) { this.Parameters = new List <FunctionParameter>(); } var matchFound = this.Parameters.Any ( m => m.Name.ToLower() == configuration.Name.ToLower() ); if (matchFound) { throw new InvalidOperationException ( "A parameter named '{0}' has already been defined.".With ( configuration.Name ) ); } var parameter = new FunctionParameter ( this, configuration ); this.Parameters.Add(parameter); }
/// <summary> /// Configures the function parameter using the details specified /// </summary> /// <param name="configuration">The configuration details</param> private void Configure ( FunctionParameterConfiguration configuration ) { Validate.IsNotNull(configuration); Validate.IsNotEmpty(configuration.Name); Validate.IsNotNull(configuration.DataType); var defaultValue = configuration.DefaultValue; this.Name = configuration.Name; this.Description = configuration.Description; this.DataType = configuration.DataType; this.Optional = configuration.Optional; this.DefaultValue = defaultValue; if (defaultValue != null) { var isValid = IsValidParameterValue ( defaultValue ); if (false == isValid) { throw new ArgumentException ( "The default value for '{0}' is not valid.".With ( this.Name ) ); } } }