Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Neo.Json into a separate project #2791

Merged
merged 9 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 11 additions & 34 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: .NET Core Test and Publish

on:
push:
branches: master
branches: [master]
pull_request:

env:
Expand All @@ -17,9 +17,9 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Check format
Expand All @@ -36,40 +36,17 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

PublishGithub:
# Because sometimes this action is not working as expected we will disable it until determine that it's more stable
if: false && github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
needs: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Setup NuGet.exe for use with actions
uses: NuGet/setup-nuget@v1
- name: Pack with dotnet
run: git rev-list --count HEAD |xargs printf "CI%05d" |xargs dotnet pack -c Debug -o out --include-source --version-suffix
- name: Publish to Github Packages
run: |
nuget source Add -Name "GitHub" -Source "https://nuget.pkg.github.com/neo-project/index.json" -UserName neo-project -Password ${GITHUB_TOKEN}
nuget push out/*.nupkg -Source "GitHub"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

PublishMyGet:
if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
needs: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Pack with dotnet
Expand All @@ -85,12 +62,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Get version
id: get_version
run: |
sudo apt install xmlstarlet
find src -name *.csproj | xargs xmlstarlet sel -t -v "concat('::set-output name=version::v',//VersionPrefix/text())" | xargs echo
find src -name Directory.Build.props | xargs xmlstarlet sel -t -v "concat('::set-output name=version::v',//VersionPrefix/text())" | xargs echo
- name: Check tag
id: check_tag
run: curl -s -I ${{ format('https://github.com/{0}/releases/tag/{1}', github.repository, steps.get_version.outputs.version) }} | head -n 1 | cut -d$' ' -f2 | xargs printf "::set-output name=statusCode::%s" | xargs echo
Expand All @@ -104,9 +81,9 @@ jobs:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}
prerelease: ${{ contains(steps.get_version.outputs.version, '-') }}
- name: Setup .NET Core
- name: Setup .NET
if: steps.check_tag.outputs.statusCode == '404'
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet
Expand Down
14 changes: 14 additions & 0 deletions neo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo", "src\Neo\Neo.csproj", "{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Json", "src\Neo.Json\Neo.Json.csproj", "{6B709ED6-64C0-451D-B07F-8F49185AE191}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.UnitTests", "tests\Neo.UnitTests\Neo.UnitTests.csproj", "{5B783B30-B422-4C2F-AC22-187A8D1993F4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Json.UnitTests", "tests\Neo.Json.UnitTests\Neo.Json.UnitTests.csproj", "{AE6C32EE-8447-4E01-8187-2AE02BB64251}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Neo.Benchmarks", "benchmarks\Neo.Benchmarks\Neo.Benchmarks.csproj", "{BCD03521-5F8F-4775-9ADF-FA361480804F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B5339DF7-5D1D-43BA-B332-74B825E1770E}"
Expand All @@ -24,10 +28,18 @@ Global
{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC}.Release|Any CPU.Build.0 = Release|Any CPU
{6B709ED6-64C0-451D-B07F-8F49185AE191}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B709ED6-64C0-451D-B07F-8F49185AE191}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B709ED6-64C0-451D-B07F-8F49185AE191}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B709ED6-64C0-451D-B07F-8F49185AE191}.Release|Any CPU.Build.0 = Release|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5B783B30-B422-4C2F-AC22-187A8D1993F4}.Release|Any CPU.Build.0 = Release|Any CPU
{AE6C32EE-8447-4E01-8187-2AE02BB64251}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AE6C32EE-8447-4E01-8187-2AE02BB64251}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AE6C32EE-8447-4E01-8187-2AE02BB64251}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AE6C32EE-8447-4E01-8187-2AE02BB64251}.Release|Any CPU.Build.0 = Release|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BCD03521-5F8F-4775-9ADF-FA361480804F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -38,7 +50,9 @@ Global
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{36447A9B-0311-4D4D-A3D5-AECBE9C15BBC} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{6B709ED6-64C0-451D-B07F-8F49185AE191} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{5B783B30-B422-4C2F-AC22-187A8D1993F4} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{AE6C32EE-8447-4E01-8187-2AE02BB64251} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{BCD03521-5F8F-4775-9ADF-FA361480804F} = {C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
17 changes: 17 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<Copyright>2015-2022 The Neo Project</Copyright>
<VersionPrefix>3.3.1</VersionPrefix>
<Authors>The Neo Project</Authors>
<TargetFramework>net6.0</TargetFramework>
<PackageProjectUrl>https://github.com/neo-project/neo</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/neo-project/neo.git</RepositoryUrl>
<Company>The Neo Project</Company>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

</Project>
55 changes: 20 additions & 35 deletions src/Neo/IO/Json/JArray.cs → src/Neo.Json/JArray.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// The Neo.Json is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
Expand All @@ -9,37 +9,35 @@
// modifications are permitted.

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;

namespace Neo.IO.Json
namespace Neo.Json
{
/// <summary>
/// Represents a JSON array.
/// </summary>
public class JArray : JObject, IList<JObject>
public class JArray : JContainer, IList<JToken?>
{
private readonly List<JObject> items = new();
private readonly List<JToken?> items = new();

/// <summary>
/// Initializes a new instance of the <see cref="JArray"/> class.
/// </summary>
/// <param name="items">The initial items in the array.</param>
public JArray(params JObject[] items) : this((IEnumerable<JObject>)items)
public JArray(params JToken?[] items) : this((IEnumerable<JToken?>)items)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="JArray"/> class.
/// </summary>
/// <param name="items">The initial items in the array.</param>
public JArray(IEnumerable<JObject> items)
public JArray(IEnumerable<JToken?> items)
{
this.items.AddRange(items);
}

public override JObject this[int index]
public override JToken? this[int index]
{
get
{
Expand All @@ -51,13 +49,7 @@ public override JObject this[int index]
}
}

public int Count
{
get
{
return items.Count;
}
}
public override IReadOnlyList<JToken?> Children => items;

public bool IsReadOnly
{
Expand All @@ -67,7 +59,7 @@ public bool IsReadOnly
}
}

public void Add(JObject item)
public void Add(JToken? item)
{
items.Add(item);
}
Expand All @@ -77,24 +69,17 @@ public override string AsString()
return string.Join(",", items.Select(p => p?.AsString()));
}

public void Clear()
public override void Clear()
{
items.Clear();
}

public bool Contains(JObject item)
public bool Contains(JToken? item)
{
return items.Contains(item);
}

public void CopyTo(JObject[] array, int arrayIndex)
{
items.CopyTo(array, arrayIndex);
}

public override JArray GetArray() => this;

public IEnumerator<JObject> GetEnumerator()
public IEnumerator<JToken?> GetEnumerator()
{
return items.GetEnumerator();
}
Expand All @@ -104,17 +89,17 @@ IEnumerator IEnumerable.GetEnumerator()
return GetEnumerator();
}

public int IndexOf(JObject item)
public int IndexOf(JToken? item)
{
return items.IndexOf(item);
}

public void Insert(int index, JObject item)
public void Insert(int index, JToken? item)
{
items.Insert(index, item);
}

public bool Remove(JObject item)
public bool Remove(JToken? item)
{
return items.Remove(item);
}
Expand All @@ -127,7 +112,7 @@ public void RemoveAt(int index)
internal override void Write(Utf8JsonWriter writer)
{
writer.WriteStartArray();
foreach (JObject item in items)
foreach (JToken? item in items)
{
if (item is null)
writer.WriteNullValue();
Expand All @@ -137,19 +122,19 @@ internal override void Write(Utf8JsonWriter writer)
writer.WriteEndArray();
}

public override JObject Clone()
public override JArray Clone()
{
var cloned = new JArray();

foreach (JObject item in items)
foreach (JToken? item in items)
{
cloned.Add(item.Clone());
cloned.Add(item?.Clone());
}

return cloned;
}

public static implicit operator JArray(JObject[] value)
public static implicit operator JArray(JToken?[] value)
{
return new JArray(value);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Neo/IO/Json/JBoolean.cs → src/Neo.Json/JBoolean.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// The Neo.Json is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
Expand All @@ -10,22 +10,22 @@

using System.Text.Json;

namespace Neo.IO.Json
namespace Neo.Json
{
/// <summary>
/// Represents a JSON boolean value.
/// </summary>
public class JBoolean : JObject
public class JBoolean : JToken
{
/// <summary>
/// Gets the value of the JSON object.
/// Gets the value of the JSON token.
/// </summary>
public bool Value { get; }

/// <summary>
/// Initializes a new instance of the <see cref="JBoolean"/> class with the specified value.
/// </summary>
/// <param name="value">The value of the JSON object.</param>
/// <param name="value">The value of the JSON token.</param>
public JBoolean(bool value = false)
{
this.Value = value;
Expand All @@ -37,7 +37,7 @@ public override bool AsBoolean()
}

/// <summary>
/// Converts the current JSON object to a floating point number.
/// Converts the current JSON token to a floating point number.
/// </summary>
/// <returns>The number 1 if value is <see langword="true"/>; otherwise, 0.</returns>
public override double AsNumber()
Expand All @@ -62,7 +62,7 @@ internal override void Write(Utf8JsonWriter writer)
writer.WriteBooleanValue(Value);
}

public override JObject Clone()
public override JBoolean Clone()
{
return this;
}
Expand Down
28 changes: 28 additions & 0 deletions src/Neo.Json/JContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (C) 2015-2022 The Neo Project.
//
// The Neo.Json is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
// project or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

namespace Neo.Json;

public abstract class JContainer : JToken
{
public override JToken? this[int index] => Children[index];

public abstract IReadOnlyList<JToken?> Children { get; }

public int Count => Children.Count;

public abstract void Clear();

public void CopyTo(JToken?[] array, int arrayIndex)
{
for (int i = 0; i < Count && i + arrayIndex < array.Length; i++)
array[i + arrayIndex] = Children[i];
}
}
Loading