Skip to content

Commit 85fb1e8

Browse files
committed
Add converter XML documentation
1 parent 98b2497 commit 85fb1e8

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

OpenSourceToolkit.Converters/Base64Converter.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,55 @@
33

44
namespace OpenSourceToolkit.Converters
55
{
6+
/// <summary>
7+
/// Provides helpers for Base64 and URL-safe Base64 text conversion.
8+
/// </summary>
69
public static class Base64Converter
710
{
11+
/// <summary>
12+
/// Encodes text as a Base64 string.
13+
/// </summary>
14+
/// <param name="text">The text to encode.</param>
15+
/// <param name="encoding">The text encoding to use, or <c>null</c> to use UTF-8.</param>
16+
/// <returns>The Base64-encoded text, or <c>null</c> when <paramref name="text"/> is <c>null</c>.</returns>
817
public static string Encode(string text, Encoding encoding = null)
918
{
1019
if (text == null) return null;
1120
var bytes = (encoding ?? Encoding.UTF8).GetBytes(text);
1221
return Convert.ToBase64String(bytes);
1322
}
1423

24+
/// <summary>
25+
/// Decodes a Base64 string to text.
26+
/// </summary>
27+
/// <param name="base64">The Base64 string to decode.</param>
28+
/// <param name="encoding">The text encoding to use, or <c>null</c> to use UTF-8.</param>
29+
/// <returns>The decoded text, or <c>null</c> when <paramref name="base64"/> is <c>null</c>.</returns>
1530
public static string Decode(string base64, Encoding encoding = null)
1631
{
1732
if (base64 == null) return null;
1833
var bytes = Convert.FromBase64String(base64);
1934
return (encoding ?? Encoding.UTF8).GetString(bytes);
2035
}
2136

37+
/// <summary>
38+
/// Encodes text as a URL-safe Base64 string without padding.
39+
/// </summary>
40+
/// <param name="text">The text to encode.</param>
41+
/// <param name="encoding">The text encoding to use, or <c>null</c> to use UTF-8.</param>
42+
/// <returns>The URL-safe Base64-encoded text.</returns>
2243
public static string EncodeUrlSafe(string text, Encoding encoding = null)
2344
{
2445
var base64 = Encode(text, encoding);
2546
return base64.Replace("+", "-").Replace("/", "_").TrimEnd('=');
2647
}
2748

49+
/// <summary>
50+
/// Decodes a URL-safe Base64 string to text.
51+
/// </summary>
52+
/// <param name="base64Url">The URL-safe Base64 string to decode.</param>
53+
/// <param name="encoding">The text encoding to use, or <c>null</c> to use UTF-8.</param>
54+
/// <returns>The decoded text.</returns>
2855
public static string DecodeUrlSafe(string base64Url, Encoding encoding = null)
2956
{
3057
var base64 = base64Url.Replace("-", "+").Replace("_", "/");

OpenSourceToolkit.Converters/EthConverter.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,49 @@
33

44
namespace OpenSourceToolkit.Converters
55
{
6+
/// <summary>
7+
/// Provides conversion helpers for Ethereum denominations.
8+
/// </summary>
69
public static class EthConverter
710
{
811
// 1 ETH = 10^18 Wei
912
// 1 Gwei = 10^9 Wei
1013

14+
/// <summary>
15+
/// Converts Ether to Wei.
16+
/// </summary>
17+
/// <param name="eth">The Ether amount.</param>
18+
/// <returns>The equivalent amount in Wei.</returns>
1119
public static decimal ToWei(decimal eth)
1220
{
1321
return eth * 1_000_000_000_000_000_000m;
1422
}
1523

24+
/// <summary>
25+
/// Converts Ether to Gwei.
26+
/// </summary>
27+
/// <param name="eth">The Ether amount.</param>
28+
/// <returns>The equivalent amount in Gwei.</returns>
1629
public static decimal ToGwei(decimal eth)
1730
{
1831
return eth * 1_000_000_000m;
1932
}
2033

34+
/// <summary>
35+
/// Converts Wei to Ether.
36+
/// </summary>
37+
/// <param name="wei">The Wei amount.</param>
38+
/// <returns>The equivalent amount in Ether.</returns>
2139
public static decimal FromWei(decimal wei)
2240
{
2341
return wei / 1_000_000_000_000_000_000m;
2442
}
2543

44+
/// <summary>
45+
/// Converts Gwei to Ether.
46+
/// </summary>
47+
/// <param name="gwei">The Gwei amount.</param>
48+
/// <returns>The equivalent amount in Ether.</returns>
2649
public static decimal FromGwei(decimal gwei)
2750
{
2851
return gwei / 1_000_000_000m;

0 commit comments

Comments
 (0)