aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Common/IPAddressConverter.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-02-15 21:57:53 -0600
committerGitHub <noreply@github.com>2021-02-15 21:57:53 -0600
commit0e9db9ca4f1a7b0f9025fa9ab277581a85afe0cb (patch)
tree9696ee0e491645958f7b48c055dbaaa879b271e9 /src/slskd/Common/IPAddressConverter.cs
parentaf1bdbcdafe5d63bfef8fb5f5e85dbc3f2352118 (diff)
parent236241ba35163a18c78bb6af60545a6c9a42a28e (diff)
downloadslskd-0e9db9ca4f1a7b0f9025fa9ab277581a85afe0cb.tar.gz
Merge pull request #42 from slskd/hosted-service
Use IHostedService for SoulseekClient
Diffstat (limited to 'src/slskd/Common/IPAddressConverter.cs')
-rw-r--r--src/slskd/Common/IPAddressConverter.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/slskd/Common/IPAddressConverter.cs b/src/slskd/Common/IPAddressConverter.cs
new file mode 100644
index 00000000..00ef5a4c
--- /dev/null
+++ b/src/slskd/Common/IPAddressConverter.cs
@@ -0,0 +1,36 @@
+// <copyright file="IPAddressConverter.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+namespace slskd
+{
+ using System;
+ using System.Net;
+ using System.Text.Json;
+ using System.Text.Json.Serialization;
+
+ /// <summary>
+ /// Serializes IPAddress instances.
+ /// </summary>
+ public class IPAddressConverter : JsonConverter<IPAddress>
+ {
+ public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(IPAddress);
+
+ public override IPAddress Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => IPAddress.Parse(reader.GetString());
+
+ public override void Write(Utf8JsonWriter writer, IPAddress value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString());
+ }
+}