Skip to content

Commit d7b9c81

Browse files
authored
Add XML comments to all public members (#561)
2 parents 4a8b36b + a5dd7dd commit d7b9c81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1504
-228
lines changed

QRCoder/ASCIIQRCode.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace QRCoder
77
{
8+
/// <summary>
9+
/// Represents an ASCII-style QR code generator that provides functionality to render QR codes as textual representations.
10+
/// </summary>
811
public class AsciiQRCode : AbstractQRCode, IDisposable
912
{
1013
/// <summary>
@@ -124,6 +127,9 @@ public string GetGraphicSmall(bool drawQuietZones = true, bool invert = false, s
124127
}
125128

126129

130+
/// <summary>
131+
/// Provides static methods for generating ASCII-style QR codes.
132+
/// </summary>
127133
public static class AsciiQRCodeHelper
128134
{
129135
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorString, string whiteSpaceString, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, string endOfLine = "\n", bool drawQuietZones = true)

QRCoder/AbstractQRCode.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,47 @@
11
namespace QRCoder
22
{
3+
/// <summary>
4+
/// Abstract base class for generating QR codes.
5+
/// Derived classes typically render a QR code into a specific format (png, System.Drawing.Bitmap, PDF, etc).
6+
/// </summary>
37
public abstract class AbstractQRCode
48
{
9+
/// <summary>
10+
/// Gets or sets the QRCodeData used to generate the QR code.
11+
/// </summary>
512
protected QRCodeData QrCodeData { get; set; }
613

14+
/// <summary>
15+
/// Initializes a new instance of the AbstractQRCode class.
16+
/// </summary>
717
protected AbstractQRCode() {
818
this.QrCodeData = null!;
919
}
1020

21+
/// <summary>
22+
/// Initializes a new instance of the AbstractQRCode class with the specified QRCodeData.
23+
/// </summary>
24+
/// <param name="data">The QRCodeData object generated by QRCodeGenerator.CreateQrCode().</param>
1125
protected AbstractQRCode(QRCodeData data) {
1226
this.QrCodeData = data;
1327
}
1428

1529
/// <summary>
16-
/// Set a QRCodeData object that will be used to generate QR code. Used in COM Objects connections
30+
/// Sets the QRCodeData object that will be used to generate the QR code.
31+
/// This method is useful for COM objects connections.
1732
/// </summary>
18-
/// <param name="data">Need a QRCodeData object generated by QRCodeGenerator.CreateQrCode()</param>
33+
/// <param name="data">The QRCodeData object generated by QRCodeGenerator.CreateQrCode().</param>
1934
virtual public void SetQRCodeData(QRCodeData data) {
2035
this.QrCodeData = data;
2136
}
2237

38+
/// <summary>
39+
/// Disposes the QRCodeData object.
40+
/// </summary>
2341
public void Dispose()
2442
{
2543
this.QrCodeData?.Dispose();
2644
this.QrCodeData = null!;
2745
}
2846
}
29-
}
47+
}

QRCoder/ArtQRCode.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@
99
// pull request raised to extend library used.
1010
namespace QRCoder
1111
{
12+
/// <summary>
13+
/// Represents an art-style QR code generator that provides functionality to render QR codes with dots as modules.
14+
/// </summary>
1215
#if NET6_0_OR_GREATER
1316
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
1417
#endif
1518
public class ArtQRCode : AbstractQRCode, IDisposable
1619
{
1720
/// <summary>
21+
/// Initializes a new instance of the <see cref="ArtQRCode"/> class.
1822
/// Constructor without params to be used in COM Objects connections
1923
/// </summary>
2024
public ArtQRCode() { }
2125

2226
/// <summary>
23-
/// Creates new ArtQrCode object
27+
/// Initializes a new instance of the <see cref="ArtQRCode"/> class with the specified <see cref="QRCodeData"/>.
2428
/// </summary>
25-
/// <param name="data">QRCodeData generated by the QRCodeGenerator</param>
29+
/// <param name="data"><see cref="QRCodeData"/> generated by the <see cref="QRCodeGenerator"/>.</param>
2630
public ArtQRCode(QRCodeData data) : base(data) { }
2731

2832
/// <summary>
@@ -256,6 +260,9 @@ public enum BackgroundImageStyle
256260
}
257261
}
258262

263+
/// <summary>
264+
/// Provides static methods for creating art-style QR codes.
265+
/// </summary>
259266
#if NET6_0_OR_GREATER
260267
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
261268
#endif

QRCoder/Base64QRCode.cs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,58 @@
99

1010
namespace QRCoder
1111
{
12+
/// <summary>
13+
/// Represents a QR code generator that outputs base64-encoded images.
14+
/// </summary>
1215
public class Base64QRCode : AbstractQRCode, IDisposable
1316
{
1417
/// <summary>
15-
/// Constructor without params to be used in COM Objects connections
18+
/// Initializes a new instance of the <see cref="Base64QRCode"/> class.
19+
/// Constructor without parameters to be used in COM objects connections.
1620
/// </summary>
1721
public Base64QRCode() {
1822
}
1923

24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="Base64QRCode"/> class with the specified <see cref="QRCodeData"/>.
26+
/// </summary>
27+
/// <param name="data"><see cref="QRCodeData"/> generated by the QRCodeGenerator.</param>
2028
public Base64QRCode(QRCodeData data) : base(data) {
2129
}
2230

31+
/// <summary>
32+
/// Returns a base64-encoded string that contains the resulting QR code as a PNG image.
33+
/// </summary>
34+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
35+
/// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
2336
public string GetGraphic(int pixelsPerModule)
2437
{
2538
return this.GetGraphic(pixelsPerModule, Color.Black, Color.White, true);
2639
}
2740

28-
41+
/// <summary>
42+
/// Returns a base64-encoded string that contains the resulting QR code as an image.
43+
/// </summary>
44+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
45+
/// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
46+
/// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
47+
/// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
48+
/// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
49+
/// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
2950
public string GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, bool drawQuietZones = true, ImageType imgType = ImageType.Png)
3051
{
3152
return this.GetGraphic(pixelsPerModule, ColorTranslator.FromHtml(darkColorHtmlHex), ColorTranslator.FromHtml(lightColorHtmlHex), drawQuietZones, imgType);
3253
}
3354

55+
/// <summary>
56+
/// Returns a base64-encoded string that contains the resulting QR code as an image.
57+
/// </summary>
58+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
59+
/// <param name="darkColor">The color of the dark modules.</param>
60+
/// <param name="lightColor">The color of the light modules.</param>
61+
/// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
62+
/// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
63+
/// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
3464
public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor, bool drawQuietZones = true, ImageType imgType = ImageType.Png)
3565
{
3666
if (imgType == ImageType.Png)
@@ -78,6 +108,18 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
78108
}
79109

80110
#if SYSTEM_DRAWING
111+
/// <summary>
112+
/// Returns a base64-encoded string that contains the resulting QR code as an image with an embedded icon.
113+
/// </summary>
114+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
115+
/// <param name="darkColor">The color of the dark modules.</param>
116+
/// <param name="lightColor">The color of the light modules.</param>
117+
/// <param name="icon">The icon to embed in the center of the QR code.</param>
118+
/// <param name="iconSizePercent">The size of the icon as a percentage of the QR code.</param>
119+
/// <param name="iconBorderWidth">The width of the border around the icon.</param>
120+
/// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
121+
/// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
122+
/// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
81123
#if NET6_0_OR_GREATER
82124
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
83125
#endif
@@ -94,6 +136,12 @@ public string GetGraphic(int pixelsPerModule, Color darkColor, Color lightColor,
94136
#endif
95137

96138
#if SYSTEM_DRAWING
139+
/// <summary>
140+
/// Converts a bitmap to a base64-encoded string.
141+
/// </summary>
142+
/// <param name="bmp">The bitmap to convert.</param>
143+
/// <param name="imgType">The type of image (PNG, JPEG, GIF).</param>
144+
/// <returns>Returns the base64-encoded string representation of the bitmap.</returns>
97145
#if NET6_0_OR_GREATER
98146
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
99147
#endif
@@ -124,23 +172,53 @@ private string BitmapToBase64(Bitmap bmp, ImageType imgType)
124172
}
125173
#endif
126174

175+
/// <summary>
176+
/// Specifies the type of image to generate.
177+
/// </summary>
127178
public enum ImageType
128179
{
129180
#if NET6_0_OR_GREATER
130181
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
131182
#endif
183+
/// <summary>
184+
/// GIF image format.
185+
/// </summary>
132186
Gif,
133187
#if NET6_0_OR_GREATER
134188
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
135189
#endif
190+
/// <summary>
191+
/// JPEG image format.
192+
/// </summary>
136193
Jpeg,
194+
/// <summary>
195+
/// PNG image format.
196+
/// </summary>
137197
Png
138198
}
139199

140200
}
141201

202+
/// <summary>
203+
/// Provides static methods for creating base64-encoded QR codes.
204+
/// </summary>
142205
public static class Base64QRCodeHelper
143206
{
207+
/// <summary>
208+
/// Creates a base64-encoded QR code with a single function call.
209+
/// </summary>
210+
/// <param name="plainText">The text or payload to be encoded inside the QR code.</param>
211+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
212+
/// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
213+
/// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
214+
/// <param name="eccLevel">The level of error correction data.</param>
215+
/// <param name="forceUtf8">Specifies whether the generator should be forced to work in UTF-8 mode.</param>
216+
/// <param name="utf8BOM">Specifies whether the byte-order-mark should be used.</param>
217+
/// <param name="eciMode">Specifies which ECI mode should be used.</param>
218+
/// <param name="requestedVersion">Sets the fixed QR code target version.</param>
219+
/// <param name="drawQuietZones">Indicates if quiet zones around the QR code should be drawn.</param>
220+
/// <param name="imgType">The type of image to generate (PNG, JPEG, GIF).</param>
221+
/// <returns>Returns the QR code graphic as a base64-encoded string.</returns>
144222
public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, ImageType imgType = ImageType.Png)
145223
{
146224
using (var qrGenerator = new QRCodeGenerator())
@@ -151,4 +229,4 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar
151229
}
152230
}
153231

154-
#endif
232+
#endif

QRCoder/BitmapByteQRCode.cs

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,53 @@
66
namespace QRCoder
77
{
88

9+
/// <summary>
10+
/// Represents a QR code generator that outputs QR codes as bitmap byte arrays.
11+
/// </summary>
912
// ReSharper disable once InconsistentNaming
1013
public class BitmapByteQRCode : AbstractQRCode, IDisposable
1114
{
1215
/// <summary>
13-
/// Constructor without params to be used in COM Objects connections
16+
/// Initializes a new instance of the <see cref="BitmapByteQRCode"/> class.
17+
/// Constructor without parameters to be used in COM objects connections.
1418
/// </summary>
1519
public BitmapByteQRCode() { }
1620

21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="BitmapByteQRCode"/> class with the specified <see cref="QRCodeData"/>.
23+
/// </summary>
24+
/// <param name="data"><see cref="QRCodeData"/> generated by the QRCodeGenerator.</param>
1725
public BitmapByteQRCode(QRCodeData data) : base(data) { }
1826

27+
/// <summary>
28+
/// Returns the QR code graphic as a bitmap byte array.
29+
/// </summary>
30+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
31+
/// <returns>Returns the QR code graphic as a bitmap byte array.</returns>
1932
public byte[] GetGraphic(int pixelsPerModule)
2033
{
2134
return GetGraphic(pixelsPerModule, new byte[] { 0x00, 0x00, 0x00 }, new byte[] { 0xFF, 0xFF, 0xFF });
2235
}
2336

37+
/// <summary>
38+
/// Returns the QR code graphic as a bitmap byte array.
39+
/// </summary>
40+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
41+
/// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
42+
/// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
43+
/// <returns>Returns the QR code graphic as a bitmap byte array.</returns>
2444
public byte[] GetGraphic(int pixelsPerModule, string darkColorHtmlHex, string lightColorHtmlHex)
2545
{
2646
return GetGraphic(pixelsPerModule, HexColorToByteArray(darkColorHtmlHex), HexColorToByteArray(lightColorHtmlHex));
2747
}
2848

49+
/// <summary>
50+
/// Returns the QR code graphic as a bitmap byte array.
51+
/// </summary>
52+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
53+
/// <param name="darkColorRgb">The color of the dark modules as an RGB byte array.</param>
54+
/// <param name="lightColorRgb">The color of the light modules as an RGB byte array.</param>
55+
/// <returns>Returns the QR code graphic as a bitmap byte array.</returns>
2956
public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightColorRgb)
3057
{
3158
var sideLength = this.QrCodeData.ModuleMatrix.Count * pixelsPerModule;
@@ -76,16 +103,26 @@ public byte[] GetGraphic(int pixelsPerModule, byte[] darkColorRgb, byte[] lightC
76103
return bmp.ToArray();
77104
}
78105

106+
/// <summary>
107+
/// Converts a hex color string to a byte array.
108+
/// </summary>
109+
/// <param name="colorString">The hex color string to convert.</param>
110+
/// <returns>Returns the color as a byte array.</returns>
79111
private byte[] HexColorToByteArray(string colorString)
80112
{
81113
if (colorString.StartsWith("#"))
82114
colorString = colorString.Substring(1);
83115
byte[] byteColor = new byte[colorString.Length / 2];
84116
for (int i = 0; i < byteColor.Length; i++)
85-
byteColor[i] = byte.Parse(colorString.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture);
117+
byteColor[i] = byte.Parse(colorString.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture);
86118
return byteColor;
87119
}
88120

121+
/// <summary>
122+
/// Converts an integer to a 4-byte array.
123+
/// </summary>
124+
/// <param name="inp">The integer to convert.</param>
125+
/// <returns>Returns the integer as a 4-byte array.</returns>
89126
private byte[] IntTo4Byte(int inp)
90127
{
91128
byte[] bytes = new byte[2];
@@ -99,8 +136,24 @@ private byte[] IntTo4Byte(int inp)
99136
}
100137

101138

139+
/// <summary>
140+
/// Provides helper functions for creating bitmap byte array QR codes.
141+
/// </summary>
102142
public static class BitmapByteQRCodeHelper
103143
{
144+
/// <summary>
145+
/// Creates a bitmap byte array QR code with a single function call.
146+
/// </summary>
147+
/// <param name="plainText">The text or payload to be encoded inside the QR code.</param>
148+
/// <param name="pixelsPerModule">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
149+
/// <param name="darkColorHtmlHex">The color of the dark modules in HTML hex format.</param>
150+
/// <param name="lightColorHtmlHex">The color of the light modules in HTML hex format.</param>
151+
/// <param name="eccLevel">The level of error correction data.</param>
152+
/// <param name="forceUtf8">Specifies whether the generator should be forced to work in UTF-8 mode.</param>
153+
/// <param name="utf8BOM">Specifies whether the byte-order-mark should be used.</param>
154+
/// <param name="eciMode">Specifies which ECI mode should be used.</param>
155+
/// <param name="requestedVersion">Sets the fixed QR code target version.</param>
156+
/// <returns>Returns the QR code graphic as a bitmap byte array.</returns>
104157
public static byte[] GetQRCode(string plainText, int pixelsPerModule, string darkColorHtmlHex,
105158
string lightColorHtmlHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false,
106159
EciMode eciMode = EciMode.Default, int requestedVersion = -1)
@@ -113,6 +166,13 @@ public static byte[] GetQRCode(string plainText, int pixelsPerModule, string dar
113166
return qrCode.GetGraphic(pixelsPerModule, darkColorHtmlHex, lightColorHtmlHex);
114167
}
115168

169+
/// <summary>
170+
/// Creates a bitmap byte array QR code with a single function call.
171+
/// </summary>
172+
/// <param name="txt">The text or payload to be encoded inside the QR code.</param>
173+
/// <param name="eccLevel">The level of error correction data.</param>
174+
/// <param name="size">The number of pixels each dark/light module of the QR code will occupy in the final QR code image.</param>
175+
/// <returns>Returns the QR code graphic as a bitmap byte array.</returns>
116176
public static byte[] GetQRCode(string txt, QRCodeGenerator.ECCLevel eccLevel, int size)
117177
{
118178
using (var qrGen = new QRCodeGenerator())

0 commit comments

Comments
 (0)