Пример #1
0
        public static object Convert(FunctionArgumentType argumentType, string argument)
        {
            switch (argumentType)
            {
            case FunctionArgumentType.None:
                if (false == String.IsNullOrWhiteSpace(argument))
                {
                    throw new InvalidArgumentException($"The argument {argument} is invalid for type {argumentType}");
                }
                return(null);

            case FunctionArgumentType.Int:
            {
                int result;
                if (false == int.TryParse(argument, out result))
                {
                    throw new InvalidArgumentException($"The argument {argument} is invalid for type {argumentType}");
                }

                return(result);
            }

            case FunctionArgumentType.Double:
            {
                double result;
                if (false == double.TryParse(argument, out result))
                {
                    throw new InvalidArgumentException($"The argument {argument} is invalid for type {argumentType}");
                }

                return(result);
            }

            default:
                throw new NotImplementedException($"{argumentType} is not implemented");
            }
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeviceFunction"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="argumentType">The type of argument the function takes</param>
 public DeviceFunction(string name, FunctionArgumentType argumentType)
 {
     this.Name         = name;
     this.ArgumentType = argumentType;
 }