Пример #1
0
        protected byte[] SwitchEncoding(byte[] bytes, EncodingType sourceEncoding, EncodingType targetEncoding)
        {
            if (sourceEncoding.Equals(targetEncoding))
            {
                return(bytes);
            }
            switch (sourceEncoding)
            {
            case EncodingType.PLAIN:
            {
                // Nothing to do
                break;
            }

            case EncodingType.BASE64:
            {
                bytes = Base64.DecodeBase64(bytes);
                break;
            }

            default:
            {
                throw new NotSupportedException(sourceEncoding + " not yet supported");
            }
            }
            switch (targetEncoding)
            {
            case EncodingType.PLAIN:
            {
                // Nothing to do
                break;
            }

            case EncodingType.BASE64:
            {
                bytes = Base64.EncodeBase64(bytes);
                break;
            }

            default:
            {
                throw new NotSupportedException(sourceEncoding + " not yet supported");
            }
            }
            return(bytes);
        }