예제 #1
0
        /// <summary>
        /// Convert <see cref="FileV2HashAlgorithm"/> to <see cref="HashAlgorithmKind"/>
        /// </summary>
        /// <param name="source">The source value</param>
        /// <returns>The <see cref="ConvertResult{TResult}"/> containing the converted value</returns>
        public ConvertResult <HashAlgorithmKind?> Convert(FileV2HashAlgorithm?source)
        {
            HashAlgorithmKind?algorithm = null;

            if (source.HasValue == true)
            {
                switch (source)
                {
                case FileV2HashAlgorithm.None:
                    algorithm = null;
                    break;

                case FileV2HashAlgorithm.SHA256:
                    algorithm = HashAlgorithmKind.SHA256;
                    break;

                case FileV2HashAlgorithm.SHA384:
                    algorithm = HashAlgorithmKind.SHA384;
                    break;

                case FileV2HashAlgorithm.SHA512:
                    algorithm = HashAlgorithmKind.SHA512;
                    break;

                default:
                    throw new ArgumentException("Unexpected value", nameof(source));
                }
            }

            return(ConvertResult.FromNullable(algorithm));
        }
        /// <summary>
        /// Convert <see cref="HttpMethod"/> to <see cref="Method"/>
        /// </summary>
        /// <param name="source">The source value</param>
        /// <returns>The <see cref="ConvertResult{TResult}"/> containing the converted value</returns>
        /// <exception cref="ArgumentException">Unsupported value</exception>
        public ConvertResult <Method?> Convert(HttpMethod?source)
        {
            Method?method;

            switch (source)
            {
            case null:
                method = null;
                break;

            case HttpMethod.Get:
                method = Method.GET;
                break;

            case HttpMethod.Post:
                method = Method.POST;
                break;

            case HttpMethod.Put:
                method = Method.PUT;
                break;

            case HttpMethod.Delete:
                method = Method.DELETE;
                break;

            case HttpMethod.Head:
                method = Method.HEAD;
                break;

            case HttpMethod.Options:
                method = Method.OPTIONS;
                break;

            case HttpMethod.Patch:
                method = Method.PATCH;
                break;

            case HttpMethod.Merge:
                method = Method.MERGE;
                break;

            case HttpMethod.Copy:
                method = Method.COPY;
                break;

            default:
                throw new ArgumentException("Unsupported value", nameof(source));
            }

            return(ConvertResult.FromNullable(method));
        }
        /// <summary>
        /// Convert <see cref="ResponseStatus"/> to <see cref="ResponseStatusCode"/>
        /// </summary>
        /// <param name="source">The source value</param>
        /// <returns>The <see cref="ConvertResult{TResult}"/> containing the converted value</returns>
        /// <exception cref="ArgumentException">Unsupported value</exception>
        public ConvertResult <ResponseStatusCode?> Convert(ResponseStatus?source)
        {
            ResponseStatusCode?code;

            switch (source)
            {
            case null:
                code = null;
                break;

            case ResponseStatus.None:
                code = ResponseStatusCode.None;
                break;

            case ResponseStatus.Completed:
                code = ResponseStatusCode.Completed;
                break;

            case ResponseStatus.Error:
                code = ResponseStatusCode.Error;
                break;

            case ResponseStatus.TimedOut:
                code = ResponseStatusCode.TimedOut;
                break;

            case ResponseStatus.Aborted:
                code = ResponseStatusCode.Aborted;
                break;

            default:
                throw new ArgumentException("Unsupported value", nameof(source));
            }

            return(ConvertResult.FromNullable(code));
        }