Skip to content

Commit 3b1c46a

Browse files
committed
Code Cleanup - Minor code cleanup
- Add Microsoft.CodeAnalysis.NetAnalyzers package - Make some classes sealed - Fix/Add xml doc
1 parent 12d28b6 commit 3b1c46a

24 files changed

+129
-23
lines changed

CefSharp.WinForms/Experimental/ChromiumRenderWidgetHandleFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static bool TryFindHandle(IBrowser browser, out IntPtr chromerRenderWidge
7878
/// Helper function used to find the child HWND with the ClassName matching <paramref name="chromeRenderWidgetHostClassName"/>
7979
/// Chromium's message-loop Window isn't created synchronously, so this may not find it.
8080
/// If so, you need to wait and try again later.
81-
/// In most cases you should use the <see cref="TryFindHandle(ChromiumWebBrowser, out IntPtr)"/> overload.
81+
/// In most cases you should use the <see cref="TryFindHandle(IWebBrowser, out IntPtr)"/> overload.
8282
/// </summary>
8383
/// <param name="chromiumWebBrowserHandle"><see cref="ChromiumWebBrowser"/> control Handle</param>
8484
/// <param name="chromeRenderWidgetHostClassName">class name used to match</param>

CefSharp.WinForms/Handler/LifeSpanHandlerBuilder.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ public class LifeSpanHandlerBuilder
1111
{
1212
private readonly LifeSpanHandler handler;
1313

14+
/// <summary>
15+
/// LifeSpanHandlerBuilder
16+
/// </summary>
17+
/// <param name="chromiumHostControlCreatedDelegate">
18+
/// When specified the delegate will be used to create the <see cref="Host.ChromiumHostControl"/>
19+
/// instance. Allowing users to create their own custom instance that extends <see cref="Host.ChromiumHostControl"/>
20+
/// </param>
1421
public LifeSpanHandlerBuilder(CreatePopupChromiumHostControl chromiumHostControlCreatedDelegate)
1522
{
1623
handler = new LifeSpanHandler(chromiumHostControlCreatedDelegate);
@@ -30,9 +37,9 @@ public LifeSpanHandlerBuilder OnBeforePopupCreated(OnBeforePopupCreatedDelegate
3037
}
3138

3239
/// <summary>
33-
/// The <see cref="OnPopupCreatedDelegate"/> will be called when the<see cref="ChromiumHostControl"/> has been
40+
/// The <see cref="OnPopupCreatedDelegate"/> will be called when the<see cref="Host.ChromiumHostControl"/> has been
3441
/// created. When the <see cref="OnPopupCreatedDelegate"/> is called you must add the control to it's intended parent
35-
/// so the <see cref="Control.ClientRectangle"/> can be calculated to set the initial
42+
/// so the <see cref="System.Windows.Forms.Control.ClientRectangle"/> can be calculated to set the initial
3643
/// size correctly.
3744
/// </summary>
3845
/// <param name="onPopupCreated">Action to be invoked when the Popup is to be destroyed.</param>
@@ -60,9 +67,9 @@ public LifeSpanHandlerBuilder OnPopupBrowserCreated(OnPopupBrowserCreatedDelegat
6067
}
6168

6269
/// <summary>
63-
/// The <see cref="OnPopupDestroyedDelegate"/> will be called when the <see cref="ChromiumHostControl"/> is to be
70+
/// The <see cref="OnPopupDestroyedDelegate"/> will be called when the <see cref="Host.ChromiumHostControl"/> is to be
6471
/// removed from it's parent.
65-
/// When the <see cref="OnPopupDestroyedDelegate"/> is called you must remove/dispose of the <see cref="ChromiumHostControl"/>.
72+
/// When the <see cref="OnPopupDestroyedDelegate"/> is called you must remove/dispose of the <see cref="Host.ChromiumHostControl"/>.
6673
/// </summary>
6774
/// <param name="onPopupDestroyed">Action to be invoked when the Popup is to be destroyed.</param>
6875
/// <returns><see cref="LifeSpanHandlerBuilder"/> instance allowing you to chain method calls together</returns>

CefSharp.WinForms/Host/ChromiumHostControl.cs

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ public void LoadUrl(string url)
242242
}
243243
}
244244

245+
/// <inheritdoc/>
245246
public Task<LoadUrlAsyncResponse> LoadUrlAsync(string url)
246247
{
247248
//LoadUrlAsync is actually a static method so that CefSharp.Wpf.HwndHost can reuse the code
@@ -264,6 +265,7 @@ public IFrame GetMainFrame()
264265
return browser.MainFrame;
265266
}
266267

268+
/// <inheritdoc/>
267269
protected override void Dispose(bool disposing)
268270
{
269271
if (disposing)

CefSharp.WinForms/WebBrowserExtensions.cs

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public static bool DestroyWindow(this IChromiumWebBrowserBase chromiumWebBrowser
6868
/// </summary>
6969
/// <param name="chromiumWebBrowser"><see cref="ChromiumWebBrowser"/> instance</param>
7070
/// <param name="parentControl">Control used as the parent for DevTools (a custom control will be added to the <see cref="Control.Controls"/> collection)</param>
71+
/// <param name="controlName">Control name</param>
72+
/// <param name="dockStyle">Dock Style</param>
7173
/// <param name="inspectElementAtX">x coordinate (used for inspectElement)</param>
7274
/// <param name="inspectElementAtY">y coordinate (used for inspectElement)</param>
7375
/// <returns>Returns the <see cref="Control"/> that hosts the DevTools instance if successful, otherwise returns null on error.</returns>
@@ -92,6 +94,8 @@ public static Control ShowDevToolsDocked(this IChromiumWebBrowserBase chromiumWe
9294
/// Action that is Invoked when the DevTools Host Control has been created and needs to be added to it's parent.
9395
/// It's important the control is added to it's intended parent at this point so the <see cref="Control.ClientRectangle"/>
9496
/// can be calculated to set the initial display size.</param>
97+
/// <param name="controlName">control name</param>
98+
/// <param name="dockStyle">Dock Style</param>
9599
/// <param name="inspectElementAtX">x coordinate (used for inspectElement)</param>
96100
/// <param name="inspectElementAtY">y coordinate (used for inspectElement)</param>
97101
/// <returns>Returns the <see cref="Control"/> that hosts the DevTools instance if successful, otherwise returns null on error.</returns>

CefSharp.Wpf/Rendering/AllocHGlobalWritableBitmapRenderHandler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace CefSharp.Wpf.Rendering
1515
{
1616
/// <summary>
1717
/// AllocHGlobalWritableBitmapRenderHandler - creates/updates an WritableBitmap
18-
/// Uses <see cref="Marshal.AllocHGlobal"/> to allocate memory for
18+
/// Uses <see cref="Marshal.AllocHGlobal(int)"/> to allocate memory for
1919
/// double buffering when the size matches or creates a new WritableBitmap
2020
/// when required.
2121
/// </summary>

CefSharp.Wpf/Rendering/Experimental/CompositionTargetRenderHandler.cs

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ public class CompositionTargetRenderHandler : IRenderHandler
2525
private readonly object lockObj = new object();
2626
private ChromiumWebBrowser browser;
2727

28+
/// <summary>
29+
/// Default constructor
30+
/// </summary>
31+
/// <param name="browser">ChromiumWebBrowser instance</param>
32+
/// <param name="dpiX">DPI X</param>
33+
/// <param name="dpiY">DPI Y</param>
2834
public CompositionTargetRenderHandler(ChromiumWebBrowser browser, double dpiX, double dpiY)
2935
{
3036
this.browser = browser;

CefSharp/Callback/NoOpCompletionCallback.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ namespace CefSharp.Callback
1111
/// that does nothing with complete.
1212
/// Added to workaround a CEF bug as per https://github.com/cefsharp/CefSharp/issues/2957#issuecomment-555285400
1313
/// </summary>
14-
public class NoOpCompletionCallback : ICompletionCallback
14+
public sealed class NoOpCompletionCallback : ICompletionCallback
1515
{
16+
/// <inheritdoc/>
1617
void ICompletionCallback.OnComplete()
1718
{
1819

1920
}
2021

22+
/// <inheritdoc/>
2123
bool ICompletionCallback.IsDisposed
2224
{
2325
//For now we return false
2426
get { return false; }
2527
}
2628

29+
/// <inheritdoc/>
2730
void IDisposable.Dispose()
2831
{
2932

CefSharp/Callback/TaskCompletionCallback.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace CefSharp
1111
/// <summary>
1212
/// Provides a callback implementation of <see cref="ICompletionCallback"/>.
1313
/// </summary>
14-
public class TaskCompletionCallback : ICompletionCallback
14+
public sealed class TaskCompletionCallback : ICompletionCallback
1515
{
1616
private readonly TaskCompletionSource<bool> taskCompletionSource;
1717
private volatile bool isDisposed;

CefSharp/CefLibraryHandle.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public CefLibraryHandle(string path) : base(IntPtr.Zero, true)
5555
/// </value>
5656
public override bool IsInvalid
5757
{
58-
get { return this.handle == IntPtr.Zero; }
58+
get { return handle == IntPtr.Zero; }
5959
}
6060

6161
/// <summary>
@@ -67,7 +67,7 @@ public override bool IsInvalid
6767
/// </returns>
6868
protected override bool ReleaseHandle()
6969
{
70-
return FreeLibrary(this.handle);
70+
return FreeLibrary(handle);
7171
}
7272

7373
[DllImport("kernel32.dll", SetLastError = true)]

CefSharp/CefSharp.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
</ItemGroup>
2323
<ItemGroup>
2424
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" />
25+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
26+
<PrivateAssets>all</PrivateAssets>
27+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28+
</PackageReference>
2529
</ItemGroup>
2630
<ItemGroup>
2731
<Compile Remove="DevTools\DevToolsClient.Generated.netcore.cs" />

CefSharp/CefSharp.netcore.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
</PropertyGroup>
2828

2929
<ItemGroup>
30+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
31+
<PrivateAssets>all</PrivateAssets>
32+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
33+
</PackageReference>
3034
<PackageReference Include="System.Text.Json" Version="5.0.0" />
3135
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
3236
</ItemGroup>

CefSharp/DevTools/DevToolsClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private static T DeserializeJson<T>(Stream stream)
377377
/// </summary>
378378
/// <param name="type">Object type</param>
379379
/// <param name="stream">JSON stream</param>
380-
/// <returns>object of type <typeparamref name="type"/></returns>
380+
/// <returns>object of type <paramref name="type"/></returns>
381381
private static object DeserializeJson(Type type, Stream stream)
382382
{
383383
#if NETCOREAPP

CefSharp/DevTools/DevToolsDomainBase.cs

+29
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,28 @@
1111

1212
namespace CefSharp.DevTools
1313
{
14+
/// <summary>
15+
/// DevTools Domain base class
16+
/// Provides some basic helper methods
17+
/// </summary>
1418
public abstract class DevToolsDomainBase
1519
{
1620
#if NETCOREAPP
21+
/// <summary>
22+
/// Convert Enum to String
23+
/// </summary>
24+
/// <param name="val">enum</param>
25+
/// <returns>string</returns>
1726
protected string EnumToString(Enum val)
1827
{
1928
return Internals.Json.JsonEnumConverterFactory.ConvertEnumToString(val);
2029
}
2130

31+
/// <summary>
32+
/// Enum to string
33+
/// </summary>
34+
/// <param name="values">array of type <see cref="CefSharp.DevTools.Network.ContentEncoding"/></param>
35+
/// <returns>enumerable string</returns>
2236
protected IEnumerable<string> EnumToString(CefSharp.DevTools.Network.ContentEncoding[] values)
2337
{
2438
foreach (var val in values)
@@ -27,6 +41,11 @@ protected IEnumerable<string> EnumToString(CefSharp.DevTools.Network.ContentEnco
2741
}
2842
}
2943

44+
/// <summary>
45+
/// Enum to string
46+
/// </summary>
47+
/// <param name="values">array of type <see cref="CefSharp.DevTools.Emulation.DisabledImageType"/></param>
48+
/// <returns>enumerable string</returns>
3049
protected IEnumerable<string> EnumToString(CefSharp.DevTools.Emulation.DisabledImageType[] values)
3150
{
3251
foreach (var val in values)
@@ -35,6 +54,11 @@ protected IEnumerable<string> EnumToString(CefSharp.DevTools.Emulation.DisabledI
3554
}
3655
}
3756

57+
/// <summary>
58+
/// Enum to string
59+
/// </summary>
60+
/// <param name="values">array of type <see cref="PermissionType"/></param>
61+
/// <returns>enumerable string</returns>
3862
protected IEnumerable<string> EnumToString(PermissionType[] values)
3963
{
4064
foreach (var val in values)
@@ -43,6 +67,11 @@ protected IEnumerable<string> EnumToString(PermissionType[] values)
4367
}
4468
}
4569

70+
/// <summary>
71+
/// Enum to string
72+
/// </summary>
73+
/// <param name="values">array of type <see cref="CefSharp.DevTools.DOMDebugger.CSPViolationType"/></param>
74+
/// <returns>enumerable string</returns>
4675
protected IEnumerable<string> EnumToString(CefSharp.DevTools.DOMDebugger.CSPViolationType[] values)
4776
{
4877
foreach (var val in values)

CefSharp/DevTools/DevToolsDomainEventArgsBase.cs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
namespace CefSharp.DevTools
99
{
10+
/// <summary>
11+
/// DevToolsDomainEventArgsBase
12+
/// </summary>
1013
[DataContract]
1114
public abstract class DevToolsDomainEventArgsBase : EventArgs
1215
{

CefSharp/DevTools/DevToolsDomainResponseBase.cs

+8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
namespace CefSharp.DevTools
66
{
7+
/// <summary>
8+
/// DevToolsDomainResponseBase
9+
/// </summary>
710
[System.Runtime.Serialization.DataContractAttribute]
811
public abstract class DevToolsDomainResponseBase
912
{
13+
/// <summary>
14+
/// Convert from string to base64 byte array
15+
/// </summary>
16+
/// <param name="data">string data</param>
17+
/// <returns>byte array</returns>
1018
public byte[] Convert(string data)
1119
{
1220
return System.Convert.FromBase64String(data);

CefSharp/DevTools/Headers.cs

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public Headers() : base(StringComparer.OrdinalIgnoreCase)
2626
{
2727
}
2828

29+
/// <summary>
30+
/// Returns itself
31+
/// </summary>
32+
/// <returns>Dictionary of headers</returns>
2933
public Dictionary<string, string> ToDictionary()
3034
{
3135
return this;

CefSharp/DevTools/MemoryDumpConfig.cs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace CefSharp.DevTools.Tracing
66
{
7+
/// <summary>
8+
/// MemoryDumpConfig
9+
/// </summary>
710
public class MemoryDumpConfig
811
{
912
}

CefSharp/Handler/IRequestHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public interface IRequestHandler
1515
{
1616
/// <summary>
1717
/// Called before browser navigation.
18-
/// If the navigation is allowed <see cref="IWebBrowser.FrameLoadStart"/> and <see cref="IWebBrowser.FrameLoadEnd"/>
19-
/// will be called. If the navigation is canceled <see cref="IWebBrowser.LoadError"/> will be called with an ErrorCode
18+
/// If the navigation is allowed <see cref="IChromiumWebBrowserBase.FrameLoadStart"/> and <see cref="IChromiumWebBrowserBase.FrameLoadEnd"/>
19+
/// will be called. If the navigation is canceled <see cref="IChromiumWebBrowserBase.LoadError"/> will be called with an ErrorCode
2020
/// value of <see cref="CefErrorCode.Aborted"/>.
2121
/// </summary>
2222
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control</param>

CefSharp/Handler/RequestHandler.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ bool IRequestHandler.OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser bro
2020
}
2121

2222
/// <summary>
23-
/// Called before browser navigation. If the navigation is allowed <see cref="IWebBrowser.FrameLoadStart"/> and
24-
/// <see cref="IWebBrowser.FrameLoadEnd"/>
25-
/// will be called. If the navigation is canceled <see cref="IWebBrowser.LoadError"/> will be called with an ErrorCode value of
23+
/// Called before browser navigation. If the navigation is allowed <see cref="IChromiumWebBrowserBase.FrameLoadStart"/> and
24+
/// <see cref="IChromiumWebBrowserBase.FrameLoadEnd"/>
25+
/// will be called. If the navigation is canceled <see cref="IChromiumWebBrowserBase.LoadError"/> will be called with an ErrorCode value of
2626
/// <see cref="CefErrorCode.Aborted"/>.
2727
/// </summary>
2828
/// <param name="chromiumWebBrowser">the ChromiumWebBrowser control.</param>

CefSharp/Internals/ConcurrentMethodRunnerQueue.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,32 @@ namespace CefSharp.Internals
1414
/// the we use ContinueWith to be notified of completion then
1515
/// raise the MethodInvocationComplete event
1616
/// </summary>
17-
public class ConcurrentMethodRunnerQueue : IMethodRunnerQueue
17+
public sealed class ConcurrentMethodRunnerQueue : IMethodRunnerQueue
1818
{
19-
private static Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult");
19+
private static readonly Type VoidTaskResultType = Type.GetType("System.Threading.Tasks.VoidTaskResult");
2020
private readonly IJavascriptObjectRepositoryInternal repository;
21-
private CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
21+
private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
2222

23+
/// <inheritdoc/>
2324
public event EventHandler<MethodInvocationCompleteArgs> MethodInvocationComplete;
2425

26+
/// <summary>
27+
/// Default constructor
28+
/// </summary>
29+
/// <param name="repository">javascript object repository</param>
2530
public ConcurrentMethodRunnerQueue(IJavascriptObjectRepositoryInternal repository)
2631
{
2732
this.repository = repository;
2833
}
2934

35+
/// <inheritdoc/>
3036
public void Dispose()
3137
{
3238
MethodInvocationComplete = null;
3339
cancellationTokenSource.Cancel();
3440
}
3541

42+
/// <inheritdoc/>
3643
public void Enqueue(MethodInvocation methodInvocation)
3744
{
3845
if (cancellationTokenSource.IsCancellationRequested)

CefSharp/Internals/IMethodRunnerQueue.cs

+10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,20 @@
66

77
namespace CefSharp.Internals
88
{
9+
/// <summary>
10+
/// Run (execute) calls made from Javascript to .Net methods
11+
/// </summary>
912
public interface IMethodRunnerQueue : IDisposable
1013
{
14+
/// <summary>
15+
/// Method invocation was completed.
16+
/// </summary>
1117
event EventHandler<MethodInvocationCompleteArgs> MethodInvocationComplete;
1218

19+
/// <summary>
20+
/// Enqueue a method invocation
21+
/// </summary>
22+
/// <param name="methodInvocation">method invocation</param>
1323
void Enqueue(MethodInvocation methodInvocation);
1424
}
1525
}

0 commit comments

Comments
 (0)