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