-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PrefsIPAddressAndPort. PrefsIPEndPoint is now obsolete.
- Loading branch information
Showing
9 changed files
with
118 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Packages/ga.fuquna.prefsgui/Runtime/PrefsElement/PrefsIPEndPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Net; | ||
|
||
namespace PrefsGUI | ||
{ | ||
[Serializable] | ||
[Obsolete("PrefsIPEndPoint is obsolete, consider using PrefsIPAddressAndPort instead.")] | ||
public class PrefsIPEndPoint : PrefsSet<PrefsString, PrefsInt, string, int> | ||
{ | ||
public string address => prefs0.Get(); | ||
public int port => prefs1.Get(); | ||
|
||
public PrefsIPEndPoint(string key, string hostname = "localhost", int port = 10000) : base(key, hostname, port, "address", "port") { } | ||
|
||
public static implicit operator IPEndPoint(PrefsIPEndPoint me) => CreateIPEndPoint(me.address, me.port); | ||
|
||
public static IPEndPoint CreateIPEndPoint(string address, int port) => | ||
IPEndPointUtility.CreateIPEndPoint(address, port); | ||
|
||
public static IPAddress FindFromHostName(string hostname) => IPEndPointUtility.FindFromHostName(hostname); | ||
} | ||
|
||
|
||
[Serializable] | ||
public class PrefsIPAddressAndPort : PrefsParam<AddressAndPort> | ||
{ | ||
public PrefsIPAddressAndPort(string key, string address = "localhost", int port = 10000) : this(key, new AddressAndPort {address = address, port = port}) | ||
{} | ||
|
||
public PrefsIPAddressAndPort(string key, AddressAndPort defaultValue) : base(key, defaultValue) | ||
{ | ||
} | ||
|
||
public static implicit operator IPEndPoint(PrefsIPAddressAndPort me) => IPEndPointUtility.CreateIPEndPoint(me.Get()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/ga.fuquna.prefsgui/Runtime/PrefsElement/PrefsIPEndPoint.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Packages/ga.fuquna.prefsgui/Runtime/Utilities/IPEndPointUtility.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
|
||
namespace PrefsGUI | ||
{ | ||
[Serializable] | ||
public struct AddressAndPort | ||
{ | ||
public string address; | ||
public int port; | ||
|
||
public void Deconstruct(out string a, out int p) | ||
{ | ||
a = address; | ||
p = port; | ||
} | ||
} | ||
|
||
|
||
public static class IPEndPointUtility | ||
{ | ||
public static IPEndPoint CreateIPEndPoint(AddressAndPort addressAndPort) | ||
{ | ||
var (address, port) = addressAndPort; | ||
return CreateIPEndPoint(address, port); | ||
} | ||
|
||
public static IPEndPoint CreateIPEndPoint(string address, int port) | ||
{ | ||
var ip = FindFromHostName(address); | ||
return (!Equals(ip, IPAddress.None)) ? new IPEndPoint(ip, port) : null; | ||
} | ||
|
||
public static IPAddress FindFromHostName(string hostname) | ||
{ | ||
var address = Dns.GetHostAddresses(hostname).FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork); | ||
return address ?? IPAddress.None; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Packages/ga.fuquna.prefsgui/Runtime/Utilities/IPEndPointUtility.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.