Skip to content

Commit b501589

Browse files
[dotnet] Add nullability annotations to print types (#14773)
1 parent 2421c66 commit b501589

File tree

7 files changed

+173
-96
lines changed

7 files changed

+173
-96
lines changed

dotnet/src/webdriver/EncodedFile.cs

+14-17
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,41 @@
1919

2020
using System;
2121

22+
#nullable enable
23+
2224
namespace OpenQA.Selenium
2325
{
2426
/// <summary>
2527
/// Represents a file transmitted over the wire as a base64-encoded string.
2628
/// </summary>
2729
public abstract class EncodedFile
2830
{
29-
private string base64Encoded = string.Empty;
30-
private byte[] byteArray;
31-
3231
/// <summary>
3332
/// Initializes a new instance of the <see cref="EncodedFile"/> class.
3433
/// </summary>
3534
/// <param name="base64EncodedFile">The file as a Base64-encoded string.</param>
35+
/// <exception cref="ArgumentNullException">If <paramref name="base64EncodedFile"/> is <see langword="null"/>.</exception>
36+
/// <exception cref="FormatException">
37+
/// <para>The length of <paramref name="base64EncodedFile"/>, ignoring white-space characters, is not zero or a multiple of 4.</para>
38+
/// <para>-or-</para>
39+
/// <para>The format of <paramref name="base64EncodedFile"/> is invalid. <paramref name="base64EncodedFile"/> contains a non-base-64 character,
40+
/// more than two padding characters, or a non-white space-character among the padding characters.</para>
41+
/// </exception>
3642
protected EncodedFile(string base64EncodedFile)
3743
{
38-
this.base64Encoded = base64EncodedFile;
39-
this.byteArray = Convert.FromBase64String(this.base64Encoded);
44+
this.AsBase64EncodedString = base64EncodedFile ?? throw new ArgumentNullException(nameof(base64EncodedFile));
45+
this.AsByteArray = Convert.FromBase64String(base64EncodedFile);
4046
}
4147

4248
/// <summary>
4349
/// Gets the value of the encoded file as a Base64-encoded string.
4450
/// </summary>
45-
public string AsBase64EncodedString
46-
{
47-
get { return this.base64Encoded; }
48-
}
51+
public string AsBase64EncodedString { get; }
4952

5053
/// <summary>
5154
/// Gets the value of the encoded file as an array of bytes.
5255
/// </summary>
53-
public byte[] AsByteArray
54-
{
55-
get { return this.byteArray; }
56-
}
56+
public byte[] AsByteArray { get; }
5757

5858
/// <summary>
5959
/// Saves the file, overwriting it if it already exists.
@@ -65,9 +65,6 @@ public byte[] AsByteArray
6565
/// Returns a <see cref="string">String</see> that represents the current <see cref="object">Object</see>.
6666
/// </summary>
6767
/// <returns>A <see cref="string">String</see> that represents the current <see cref="object">Object</see>.</returns>
68-
public override string ToString()
69-
{
70-
return this.base64Encoded;
71-
}
68+
public override string ToString() => this.AsBase64EncodedString;
7269
}
7370
}

dotnet/src/webdriver/ISupportsPrint.cs

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
// under the License.
1818
// </copyright>
1919

20+
using System;
21+
22+
#nullable enable
23+
2024
namespace OpenQA.Selenium
2125
{
2226
/// <summary>
@@ -29,6 +33,7 @@ public interface ISupportsPrint
2933
/// </summary>
3034
/// <param name="options">A <see cref="PrintOptions"/> object describing the options of the printed document.</param>
3135
/// <returns>The <see cref="PrintDocument"/> object containing the PDF-formatted print representation of the page.</returns>
36+
/// <exception cref="ArgumentNullException">If <paramref name="options"/> is <see langword="null"/>.</exception>
3237
PrintDocument Print(PrintOptions options);
3338
}
3439
}

dotnet/src/webdriver/PrintDocument.cs

+17
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
using System;
2121
using System.IO;
2222

23+
#nullable enable
24+
2325
namespace OpenQA.Selenium
2426
{
2527
/// <summary>
@@ -31,6 +33,13 @@ public class PrintDocument : EncodedFile
3133
/// Initializes a new instance of the <see cref="PrintDocument"/> class.
3234
/// </summary>
3335
/// <param name="base64EncodedDocument">The printed document as a Base64-encoded string.</param>
36+
/// <exception cref="ArgumentNullException">If <paramref name="base64EncodedDocument"/> is <see langword="null"/>.</exception>
37+
/// <exception cref="FormatException">
38+
/// <para>The length of <paramref name="base64EncodedDocument"/>, ignoring white-space characters, is not zero or a multiple of 4.</para>
39+
/// <para>-or-</para>
40+
/// <para>The format of <paramref name="base64EncodedDocument"/> is invalid. <paramref name="base64EncodedDocument"/> contains a non-base-64 character,
41+
/// more than two padding characters, or a non-white space-character among the padding characters.</para>
42+
/// </exception>
3443
public PrintDocument(string base64EncodedDocument) : base(base64EncodedDocument)
3544
{
3645
}
@@ -39,6 +48,14 @@ public PrintDocument(string base64EncodedDocument) : base(base64EncodedDocument)
3948
/// Saves this <see cref="PrintDocument"/> as a PDF formatted file, overwriting the file if it already exists.
4049
/// </summary>
4150
/// <param name="fileName">The full path and file name to save the printed document to.</param>
51+
/// <exception cref="ArgumentException">
52+
/// <para>If <paramref name="fileName"/> is <see langword="null"/> or whitespace.</para>
53+
/// <para>-or-</para>
54+
/// <para><paramref name="fileName"/> refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in an NTFS environment.</para>
55+
/// </exception>
56+
/// <exception cref="NotSupportedException"><paramref name="fileName"/> refers to a non-file device, such as "con:", "com1:", "lpt1:", etc. in a non-NTFS environment.</exception>
57+
/// <exception cref="DirectoryNotFoundException">The specified path is invalid, such as being on an unmapped drive.</exception>
58+
/// <exception cref="PathTooLongException">The specified path, file name, or both exceed the system-defined maximum length.</exception>
4259
public override void SaveAsFile(string fileName)
4360
{
4461
if (string.IsNullOrEmpty(fileName))

0 commit comments

Comments
 (0)