diff options
author | JP Ungaretti <git@jungaretti.com> | 2023-03-01 11:10:34 +0300 |
---|---|---|
committer | JP Ungaretti <git@jungaretti.com> | 2023-03-01 11:10:34 +0300 |
commit | a091bc67ddee6f5b96aaf75b5bfab8b30fe0c41d (patch) | |
tree | 5cbf4752e3669df8daf42b95890eb8f37137f927 | |
parent | ab802885688efb5dd5410421ea2c3d1151d24e8c (diff) |
Add example_project
-rw-r--r-- | test/dotnet/example_project/.gitignore | 2 | ||||
-rw-r--r-- | test/dotnet/example_project/Movie.cs | 8 | ||||
-rw-r--r-- | test/dotnet/example_project/Program.cs | 27 | ||||
-rw-r--r-- | test/dotnet/example_project/example_project.csproj | 14 |
4 files changed, 51 insertions, 0 deletions
diff --git a/test/dotnet/example_project/.gitignore b/test/dotnet/example_project/.gitignore new file mode 100644 index 0000000..1746e32 --- /dev/null +++ b/test/dotnet/example_project/.gitignore @@ -0,0 +1,2 @@ +bin +obj diff --git a/test/dotnet/example_project/Movie.cs b/test/dotnet/example_project/Movie.cs new file mode 100644 index 0000000..9d549ef --- /dev/null +++ b/test/dotnet/example_project/Movie.cs @@ -0,0 +1,8 @@ +// See https://aka.ms/new-console-template for more information + +internal class Movie +{ + public string Name { get; set; } = "Default Name"; + public DateTime ReleaseDate { get; set; } + public List<string> Genres { get; set; } = new List<string>(); +} diff --git a/test/dotnet/example_project/Program.cs b/test/dotnet/example_project/Program.cs new file mode 100644 index 0000000..7beb65f --- /dev/null +++ b/test/dotnet/example_project/Program.cs @@ -0,0 +1,27 @@ +// See https://aka.ms/new-console-template for more information
+
+using Newtonsoft.Json;
+
+Console.WriteLine("Hello, World!");
+
+string json = @"{
+ 'Name': 'Inception',
+ 'ReleaseDate': '2010-07-08T00:00:00',
+ 'Genres': [
+ 'Action',
+ 'Thriller'
+ ]
+}";
+
+Movie? m = JsonConvert.DeserializeObject<Movie>(json);
+
+if (m == default)
+{
+ Console.WriteLine("Decoding failed!");
+}
+else
+{
+ Console.WriteLine($"Name: {m.Name}");
+ Console.WriteLine($"Release Date: {m.ReleaseDate}");
+ Console.WriteLine($"Genres: {string.Join(", ", m.Genres)}");
+}
diff --git a/test/dotnet/example_project/example_project.csproj b/test/dotnet/example_project/example_project.csproj new file mode 100644 index 0000000..6132c9e --- /dev/null +++ b/test/dotnet/example_project/example_project.csproj @@ -0,0 +1,14 @@ +<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ </PropertyGroup>
+
+ <ItemGroup> + <PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> + </ItemGroup>
+
+</Project>
|