Skip to content

Commit 60552bb

Browse files
committed
feat: 增加 GetOrCreate 扩展方法
1 parent a2767ab commit 60552bb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the Apache 2.0 License
3+
// See the LICENSE file in the project root for more information.
4+
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
5+
6+
using System.Runtime.Versioning;
7+
8+
namespace BootstrapBlazor.Components;
9+
10+
/// <summary>
11+
/// <see cref="ITcpSocketFactory"/> 扩展方法类
12+
/// </summary>
13+
[UnsupportedOSPlatform("browser")]
14+
public static class ITcpSocketFactoryExtensions
15+
{
16+
/// <summary>
17+
/// Retrieves an existing TCP socket client by name or creates a new one using the specified IP address and port.
18+
/// </summary>
19+
/// <param name="factory">The <see cref="ITcpSocketFactory"/> instance used to manage TCP socket clients.</param>
20+
/// <param name="name">The unique name identifying the TCP socket client. Cannot be null or empty.</param>
21+
/// <param name="ipAddress">The IP address of the endpoint to connect to. Must be a valid IPv4 or IPv6 address.</param>
22+
/// <param name="port">The port number of the endpoint to connect to. Must be within the range 0 to 65535.</param>
23+
/// <returns>An <see cref="ITcpSocketClient"/> instance representing the TCP socket client associated with the specified
24+
/// name. If no client exists with the given name, a new client is created and returned.</returns>
25+
public static ITcpSocketClient GetOrCreate(this ITcpSocketFactory factory, string name, string ipAddress, int port)
26+
{
27+
var endPoint = Utility.ConvertToIpEndPoint(ipAddress, port);
28+
return factory.GetOrCreate(name, endPoint);
29+
}
30+
}

0 commit comments

Comments
 (0)