Skip to content

Commit ada6826

Browse files
authored
fix CA1063 (#1470)
1 parent a29f5f4 commit ada6826

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

lib/PuppeteerSharp.ruleset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
<Rule Id="CA1031" Action="None" /> <!-- Error CA1031: Modify 'SendAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
6767
<Rule Id="CA1032" Action="None" /> <!-- Error CA1032: Add the following constructor to SelectorException: public SelectorException(). (CA1032) -->
6868
<Rule Id="CA1062" Action="None" /> <!-- Error CA1031: Modify 'DeleteAsync' to catch a more specific allowed exception type, or rethrow the exception. (CA1031)-->
69-
<Rule Id="CA1063" Action="None" /> <!-- Error CA1063: Provide an overridable implementation of Dispose(bool) -->
69+
<Rule Id="CA1063" Action="Error" /> <!-- Error CA1063: Provide an overridable implementation of Dispose(bool) -->
7070
<Rule Id="CA1064" Action="None" /> <!-- Error CA1064: Exceptions should be public (CA1064)-->
7171
<Rule Id="CA1001" Action="None" /> <!-- Error CA1001: A class owns a disposable -->
7272
<Rule Id="CA1304" Action="None" /> <!-- Error CA1304: The behavior of 'string.ToLower()' could vary based on the current user's locale settings. Replace this call in 'JSHandle.ToString()' with a call to 'string.ToLower(CultureInfo)'. (CA1304) -->

lib/PuppeteerSharp/Browser.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,19 @@ internal static async Task<Browser> CreateAsync(
530530

531531
#region IDisposable
532532

533+
/// <inheritdoc />
534+
public void Dispose()
535+
{
536+
Dispose(true);
537+
GC.SuppressFinalize(this);
538+
}
539+
533540
/// <summary>
534541
/// Closes <see cref="Connection"/> and any Chromium <see cref="Process"/> that was
535542
/// created by Puppeteer.
536543
/// </summary>
537-
public void Dispose() => _ = CloseAsync();
544+
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
545+
protected virtual void Dispose(bool disposing) => _ = CloseAsync();
538546

539547
#endregion
540548

@@ -549,4 +557,4 @@ internal static async Task<Browser> CreateAsync(
549557

550558
#endregion
551559
}
552-
}
560+
}

lib/PuppeteerSharp/ChromiumProcess.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Diagnostics;
@@ -117,8 +117,8 @@ public ChromiumProcess(string chromiumExecutable, LaunchOptions options, ILogger
117117
/// <inheritdoc />
118118
public void Dispose()
119119
{
120-
GC.SuppressFinalize(this);
121120
Dispose(true);
121+
GC.SuppressFinalize(this);
122122
}
123123

124124
/// <summary>

lib/PuppeteerSharp/Connection.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Concurrent;
33
using System.Linq;
44
using System.Threading;
@@ -296,20 +296,28 @@ internal static async Task<Connection> Create(string url, IConnectionOptions con
296296
return new Connection(url, connectionOptions.SlowMo, transport, loggerFactory);
297297
}
298298

299+
/// <inheritdoc />
300+
public void Dispose()
301+
{
302+
Dispose(true);
303+
GC.SuppressFinalize(this);
304+
}
305+
299306
/// <summary>
300307
/// Releases all resource used by the <see cref="Connection"/> object.
301308
/// It will raise the <see cref="Disconnected"/> event and dispose <see cref="Transport"/>.
302309
/// </summary>
303-
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Connection"/>. The
304-
/// <see cref="Dispose"/> method leaves the <see cref="Connection"/> in an unusable state.
305-
/// After calling <see cref="Dispose"/>, you must release all references to the
310+
/// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="Connection"/>. The
311+
/// <see cref="Dispose()"/> method leaves the <see cref="Connection"/> in an unusable state.
312+
/// After calling <see cref="Dispose()"/>, you must release all references to the
306313
/// <see cref="Connection"/> so the garbage collector can reclaim the memory that the
307314
/// <see cref="Connection"/> was occupying.</remarks>
308-
public void Dispose()
315+
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
316+
protected virtual void Dispose(bool disposing)
309317
{
310318
Close("Connection disposed");
311319
Transport.Dispose();
312320
}
313321
#endregion
314322
}
315-
}
323+
}

lib/PuppeteerSharp/Page.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,14 +2421,23 @@ string SerializeArgument(object arg)
24212421
#endregion
24222422

24232423
#region IDisposable
2424+
2425+
/// <inheritdoc />
2426+
public void Dispose()
2427+
{
2428+
Dispose(true);
2429+
GC.SuppressFinalize(this);
2430+
}
2431+
24242432
/// <summary>
24252433
/// Releases all resource used by the <see cref="Page"/> object by calling the <see cref="CloseAsync"/> method.
24262434
/// </summary>
2427-
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="Page"/>. The
2428-
/// <see cref="Dispose"/> method leaves the <see cref="Page"/> in an unusable state. After
2429-
/// calling <see cref="Dispose"/>, you must release all references to the <see cref="Page"/> so
2435+
/// <remarks>Call <see cref="Dispose()"/> when you are finished using the <see cref="Page"/>. The
2436+
/// <see cref="Dispose()"/> method leaves the <see cref="Page"/> in an unusable state. After
2437+
/// calling <see cref="Dispose()"/>, you must release all references to the <see cref="Page"/> so
24302438
/// the garbage collector can reclaim the memory that the <see cref="Page"/> was occupying.</remarks>
2431-
public void Dispose() => CloseAsync();
2439+
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
2440+
protected virtual void Dispose(bool disposing) => _ = CloseAsync();
24322441
#endregion
24332442

24342443
#region IAsyncDisposable

lib/PuppeteerSharp/Transport/WebSocketTransport.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Net.WebSockets;
33
using System.Text;
44
using System.Threading;
@@ -138,6 +138,16 @@ public void StopReading()
138138

139139
/// <inheritdoc/>
140140
public void Dispose()
141+
{
142+
Dispose(true);
143+
GC.SuppressFinalize(this);
144+
}
145+
146+
/// <summary>
147+
/// Close the WebSocketTransport
148+
/// </summary>
149+
/// <param name="disposing">Indicates whether disposal was initiated by <see cref="Dispose()"/> operation.</param>
150+
protected virtual void Dispose(bool disposing)
141151
{
142152
// Make sure any outstanding asynchronous read operation is cancelled.
143153
StopReading();

0 commit comments

Comments
 (0)