Added Clone(), switched to .NET7
parent
ccd0a507bc
commit
f1aca689be
|
@ -88,6 +88,7 @@ namespace ln.json.tests
|
|||
TestEnumSerialization(testEnum3.C);
|
||||
TestEnumSerialization(testEnum3.D);
|
||||
TestEnumSerialization(testEnum3.E);
|
||||
TestEnumSerialization((testEnum3)23);
|
||||
}
|
||||
|
||||
bool TestEnumSerialization(object enumValue)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -41,6 +41,14 @@ namespace ln.json
|
|||
public JSONArray Add(JSONValue value){ values.Add(value); return this; }
|
||||
public JSONArray Remove(int index) { values.RemoveAt(index); return this; }
|
||||
|
||||
public override JSONValue Clone()
|
||||
{
|
||||
JSONArray copy = new JSONArray();
|
||||
foreach (var value in values)
|
||||
copy.Add(value.Clone());
|
||||
return copy;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ namespace ln.json
|
|||
{
|
||||
this.decValue = decValue;
|
||||
}
|
||||
|
||||
public override JSONValue Clone() => new JSONNumber(this.decValue);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
|
@ -71,6 +71,14 @@ namespace ln.json
|
|||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override JSONValue Clone()
|
||||
{
|
||||
JSONObject copy = new JSONObject();
|
||||
foreach (var key in Keys)
|
||||
copy[key] = this[key].Clone();
|
||||
return copy;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace ln.json
|
|||
{
|
||||
public static JSONTrue Instance { get; } = new JSONTrue();
|
||||
private JSONTrue() : base(JSONValueType.TRUE) { }
|
||||
public override JSONValue Clone() => this;
|
||||
|
||||
public override string ToString() => "true";
|
||||
public override object ToNative() => true;
|
||||
}
|
||||
|
@ -12,6 +14,8 @@ namespace ln.json
|
|||
{
|
||||
public static JSONFalse Instance { get; } = new JSONFalse();
|
||||
private JSONFalse() : base(JSONValueType.FALSE) { }
|
||||
public override JSONValue Clone() => this;
|
||||
|
||||
public override string ToString() => "false";
|
||||
public override object ToNative() => false;
|
||||
}
|
||||
|
@ -19,6 +23,8 @@ namespace ln.json
|
|||
{
|
||||
public static JSONNull Instance { get; } = new JSONNull();
|
||||
private JSONNull() : base(JSONValueType.NULL) { }
|
||||
public override JSONValue Clone() => this;
|
||||
|
||||
public override string ToString() => "null";
|
||||
public override object ToNative() => null;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace ln.json
|
|||
Value = value;
|
||||
}
|
||||
|
||||
public override JSONValue Clone() => new JSONString(Value);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("\"{0}\"", Escape(Value));
|
||||
|
|
|
@ -44,6 +44,8 @@ namespace ln.json
|
|||
set => throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public abstract JSONValue Clone();
|
||||
|
||||
public override string ToString() => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<AssemblyVersion>0.1.0.0</AssemblyVersion>
|
||||
<FileVersion>0.1.0.0</FileVersion>
|
||||
<PackageVersion>1.2.4</PackageVersion>
|
||||
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
|
||||
<PackageVersion>1.3.0-preview1</PackageVersion>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -155,6 +155,12 @@ namespace ln.json.mapping
|
|||
|
||||
public virtual bool Serialize(object o, out JSONValue json)
|
||||
{
|
||||
if (o is JSONValue jValue)
|
||||
{
|
||||
json = jValue.Clone();
|
||||
return true;
|
||||
}
|
||||
|
||||
lock (mappings)
|
||||
{
|
||||
if (object.ReferenceEquals(null, o))
|
||||
|
@ -224,6 +230,13 @@ namespace ln.json.mapping
|
|||
{
|
||||
o = null;
|
||||
|
||||
if (nativeType.IsSubclassOf(typeof(JSONValue)))
|
||||
{
|
||||
o = json.Clone();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (JSONNull.Instance.Equals(json))
|
||||
return true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue