Skip to content

Commit cc191f2

Browse files
committed
refactor: 重构代码
1 parent a1ccad8 commit cc191f2

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/extensions/BootstrapBlazor.OpcDa/OpcServer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace BootstrapBlazor.OpcDa;
1313
/// OPC Server 操作类
1414
/// </summary>
1515
[SupportedOSPlatform("windows")]
16-
class OpcServer : IOpcServer
16+
sealed class OpcServer : IOpcServer
1717
{
1818
private Opc.Da.Server? _server = null;
1919
private readonly ConcurrentDictionary<string, HashSet<OpcReadItem>> _valuesCache = [];
@@ -54,7 +54,7 @@ public void Disconnect()
5454
{
5555
ServerName = string.Empty;
5656

57-
if (_server != null && _server.IsConnected)
57+
if (_server is { IsConnected: true })
5858
{
5959
foreach (Subscription sub in _server.Subscriptions)
6060
{
@@ -127,7 +127,7 @@ public HashSet<OpcWriteItem> Write(params HashSet<OpcWriteItem> items)
127127

128128
private Opc.Da.Server GetOpcServer()
129129
{
130-
if (_server == null)
130+
if (_server is not { IsConnected: true })
131131
{
132132
throw new InvalidOperationException("OPC Server is not connected.");
133133
}
@@ -138,7 +138,7 @@ private Opc.Da.Server GetOpcServer()
138138
/// Dispose 方法
139139
/// </summary>
140140
/// <param name="disposing"></param>
141-
protected virtual void Dispose(bool disposing)
141+
private void Dispose(bool disposing)
142142
{
143143
if (disposing)
144144
{

0 commit comments

Comments
 (0)