target netstandard2.0 for Pilz.Configuration
This commit is contained in:
@@ -2,5 +2,7 @@
|
||||
|
||||
public interface ISettingsIdentifier
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
static abstract string Identifier { get; }
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>net8.0;netstandard2.0</TargetFrameworks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>3.2.6</Version>
|
||||
<Version>3.2.7</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Settings : ISettings
|
||||
public virtual T Get<T>() where T : ISettingsNode, ISettingsIdentifier
|
||||
{
|
||||
// Find existing one
|
||||
if (settings.TryGetValue(T.Identifier, out var valueExisting) && valueExisting is T settingsExisting)
|
||||
if (settings.TryGetValue(GetIdentifier<T>(), out var valueExisting) && valueExisting is T settingsExisting)
|
||||
return settingsExisting;
|
||||
|
||||
// Create new & reset
|
||||
@@ -27,11 +27,11 @@ public class Settings : ISettings
|
||||
else
|
||||
{
|
||||
settingsNew = default;
|
||||
Logger.WarnFormat("Not able to create new settings node instance {0}.", T.Identifier);
|
||||
Logger.WarnFormat("Not able to create new settings node instance {0}.", GetIdentifier<T>());
|
||||
}
|
||||
|
||||
// Try deserialize
|
||||
if (settingsJson.TryGetValue(T.Identifier, out var valueRaw))
|
||||
if (settingsJson.TryGetValue(GetIdentifier<T>(), out var valueRaw))
|
||||
{
|
||||
var serializer = JsonSerializer.CreateDefault(serializerSettings);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class Settings : ISettings
|
||||
try
|
||||
{
|
||||
serializer.Populate(valueRaw.CreateReader(), settingsNew);
|
||||
Logger.InfoFormat("Populated settings node {0}.", T.Identifier);
|
||||
Logger.InfoFormat("Populated settings node {0}.", GetIdentifier<T>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ public class Settings : ISettings
|
||||
try
|
||||
{
|
||||
settingsNew = settingsDeserialized;
|
||||
Logger.WarnFormat("Deserialied settings node {0} via fallback variant.", T.Identifier);
|
||||
Logger.WarnFormat("Deserialied settings node {0} via fallback variant.", GetIdentifier<T>());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public class Settings : ISettings
|
||||
|
||||
// Remember
|
||||
if (settingsNew != null)
|
||||
settings[T.Identifier] = settingsNew;
|
||||
settings[GetIdentifier<T>()] = settingsNew;
|
||||
|
||||
// Return
|
||||
return settingsNew;
|
||||
@@ -86,7 +86,6 @@ public class Settings : ISettings
|
||||
foreach (var kvp in settings)
|
||||
{
|
||||
var raw = JObject.FromObject(kvp.Value, serializer);
|
||||
if (!settingsJson.TryAdd(kvp.Key, raw))
|
||||
settingsJson[kvp.Key] = raw;
|
||||
}
|
||||
|
||||
@@ -130,4 +129,15 @@ public class Settings : ISettings
|
||||
jsonSerializer.Serialize(jTokenWriter, o, o.GetType());
|
||||
return jTokenWriter.Token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected static string GetIdentifier<T>() where T : ISettingsIdentifier
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
return T.Identifier;
|
||||
#else
|
||||
return typeof(T).GetProperty("Identifier", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).GetValue(null) as string;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user