File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/MADE.Data.Converters/Extensions Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 33
44namespace MADE . Data . Converters . Extensions
55{
6+ using System ;
67 using System . Text ;
78
89 /// <summary>
@@ -84,6 +85,33 @@ public static string ToDefaultCase(this string value)
8485 return result ;
8586 }
8687
88+ /// <summary>
89+ /// Converts a value to a Base64 string using the specified encoding.
90+ /// <para>
91+ /// Default encoding is UTF-8.
92+ /// </para>
93+ /// </summary>
94+ /// <param name="value">The string value to convert.</param>
95+ /// <param name="encoding">The encoding to get the value bytes while converting.</param>
96+ /// <returns>The Base64 string representing the value.</returns>
97+ public static string ToBase64 ( this string value , Encoding encoding = default )
98+ {
99+ encoding ??= Encoding . UTF8 ;
100+ return Convert . ToBase64String ( encoding . GetBytes ( value ) ) ;
101+ }
102+
103+ /// <summary>
104+ /// Converts a Base64 string to a value using the specified encoding.
105+ /// </summary>
106+ /// <param name="base64Value">The Base64 value to convert.</param>
107+ /// <param name="encoding">The encoding to get the value string while converting.</param>
108+ /// <returns>The string value representing the Base64 string.</returns>
109+ public static string FromBase64 ( this string base64Value , Encoding encoding = default )
110+ {
111+ encoding ??= Encoding . UTF8 ;
112+ return encoding . GetString ( Convert . FromBase64String ( base64Value ) ) ;
113+ }
114+
87115 /// <summary>
88116 /// Converts a string value to an integer.
89117 /// </summary>
You can’t perform that action at this time.
0 commit comments