private static bool TryGetCommandName(
            IDictionary <string, object> valueSet,
            out ServiceCommandName commandName,
            out IServiceCommandResponse errorResponse)
        {
            if (!valueSet.TryGetValue(ParamName.CommandName.ToString(), out object rawValue))
            {
                errorResponse = ServiceCommandResponse.CreateError(
                    ServiceCommandName.Unknown,
                    ServiceErrorInfo.MissingRequiredMessageValue(ParamName.CommandName));
                commandName = ServiceCommandName.Unknown;
                return(false);
            }

            if (!Enum.TryParse(rawValue.ToString(), out commandName))
            {
                errorResponse = ServiceCommandResponse.CreateError(
                    ServiceCommandName.Unknown,
                    ServiceErrorInfo.WrongMessageValueType(
                        ParamName.CommandName,
                        rawValue.GetType(),
                        typeof(ServiceCommandName)));
                commandName = ServiceCommandName.Unknown;
                return(false);
            }

            errorResponse = null;
            return(true);
        }
 private bool TryConvertEnumValue <T>(ParamName paramName, object rawValue, out T value) where T : struct
 {
     try
     {
         value = (T)Enum.Parse(typeof(T), rawValue.ToString());
         return(true);
     }
     catch (Exception e) when(e is ArgumentException || e is OverflowException)
     {
         LastError = ServiceCommandResponse.CreateError(
             CommandName,
             ServiceErrorInfo.WrongMessageValueType(paramName, rawValue.GetType(), typeof(T)));
         value = default(T);
         return(false);
     }
 }
        public string GetStringValue(ParamName paramName)
        {
            if (!GetRequiredValue(paramName, out object rawValue))
            {
                return(null);
            }

            if (rawValue is string value)
            {
                return(value);
            }

            LastError = ServiceCommandResponse.CreateError(
                CommandName,
                ServiceErrorInfo.WrongMessageValueType(paramName, rawValue.GetType(), typeof(string)));
            return(null);
        }
        public int GetIntValue(ParamName paramName)
        {
            if (!GetRequiredValue(paramName, out object rawValue))
            {
                return(0);
            }

            if (rawValue is int value)
            {
                return(value);
            }

            LastError = ServiceCommandResponse.CreateError(
                CommandName,
                ServiceErrorInfo.WrongMessageValueType(paramName, rawValue.GetType(), typeof(int)));
            return(0);
        }