Skip to content

Commit d5452f8

Browse files
committed
Core changes to support a pending types package
1 parent cd434a6 commit d5452f8

25 files changed

+2759
-2677
lines changed

Schema.NET.sln

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
9191
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
9292
EndProjectSection
9393
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schema.NET.Pending", "Source\Schema.NET.Pending\Schema.NET.Pending.csproj", "{4EDF33FF-4532-4328-A158-D026C66537BA}"
95+
EndProject
96+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{AF228B8A-7290-4E26-8506-934C290C6AE3}"
97+
ProjectSection(SolutionItems) = preProject
98+
Source\Common\ContactType.cs = Source\Common\ContactType.cs
99+
Source\Common\ContextJsonConverter.cs = Source\Common\ContextJsonConverter.cs
100+
Source\Common\DateTimeHelper.cs = Source\Common\DateTimeHelper.cs
101+
Source\Common\DateTimeToIso8601DateValuesJsonConverter.cs = Source\Common\DateTimeToIso8601DateValuesJsonConverter.cs
102+
Source\Common\EnumHelper.cs = Source\Common\EnumHelper.cs
103+
Source\Common\FastActivator.cs = Source\Common\FastActivator.cs
104+
Source\Common\HashCode.cs = Source\Common\HashCode.cs
105+
Source\Common\IValues.cs = Source\Common\IValues.cs
106+
Source\Common\JsonLdContext.cs = Source\Common\JsonLdContext.cs
107+
Source\Common\JsonLdObject.cs = Source\Common\JsonLdObject.cs
108+
Source\Common\OneOrMany{T}.cs = Source\Common\OneOrMany{T}.cs
109+
Source\Common\PropertyValueSpecification.Partial.cs = Source\Common\PropertyValueSpecification.Partial.cs
110+
Source\Common\SchemaSerializer.cs = Source\Common\SchemaSerializer.cs
111+
Source\Common\Thing.Partial.cs = Source\Common\Thing.Partial.cs
112+
Source\Common\TimeSpanToISO8601DurationValuesJsonConverter.cs = Source\Common\TimeSpanToISO8601DurationValuesJsonConverter.cs
113+
Source\Common\TypeExtensions.cs = Source\Common\TypeExtensions.cs
114+
Source\Common\ValuesJsonConverter.cs = Source\Common\ValuesJsonConverter.cs
115+
Source\Common\Values{T1,T2,T3,T4,T5,T6,T7}.cs = Source\Common\Values{T1,T2,T3,T4,T5,T6,T7}.cs
116+
Source\Common\Values{T1,T2,T3,T4}.cs = Source\Common\Values{T1,T2,T3,T4}.cs
117+
Source\Common\Values{T1,T2,T3}.cs = Source\Common\Values{T1,T2,T3}.cs
118+
Source\Common\Values{T1,T2}.cs = Source\Common\Values{T1,T2}.cs
119+
EndProjectSection
120+
EndProject
94121
Global
95122
GlobalSection(SolutionConfigurationPlatforms) = preSolution
96123
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +140,10 @@ Global
113140
{379FE111-579B-4A3A-9E49-40D8E2904883}.Debug|Any CPU.Build.0 = Debug|Any CPU
114141
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.ActiveCfg = Release|Any CPU
115142
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.Build.0 = Release|Any CPU
143+
{4EDF33FF-4532-4328-A158-D026C66537BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
144+
{4EDF33FF-4532-4328-A158-D026C66537BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
145+
{4EDF33FF-4532-4328-A158-D026C66537BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
146+
{4EDF33FF-4532-4328-A158-D026C66537BA}.Release|Any CPU.Build.0 = Release|Any CPU
116147
EndGlobalSection
117148
GlobalSection(SolutionProperties) = preSolution
118149
HideSolutionNode = FALSE
@@ -126,6 +157,8 @@ Global
126157
{379FE111-579B-4A3A-9E49-40D8E2904883} = {1D81D082-9C25-4D4E-890E-9CD173532307}
127158
{040F8F6D-9144-42FD-9B0D-7F88EF0C26C5} = {F20E2797-D1E3-4321-91BB-FAE54954D2A0}
128159
{9444439E-8476-4BAB-AE1E-DBC24B58865F} = {040F8F6D-9144-42FD-9B0D-7F88EF0C26C5}
160+
{4EDF33FF-4532-4328-A158-D026C66537BA} = {719809C2-A551-4C4A-9EFD-B10FB5E35BC0}
161+
{AF228B8A-7290-4E26-8506-934C290C6AE3} = {719809C2-A551-4C4A-9EFD-B10FB5E35BC0}
129162
EndGlobalSection
130163
GlobalSection(ExtensibilityGlobals) = postSolution
131164
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}
File renamed without changes.
Lines changed: 89 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
1-
namespace Schema.NET
2-
{
3-
using System;
4-
using Newtonsoft.Json;
5-
using Newtonsoft.Json.Linq;
6-
7-
/// <summary>
8-
/// Converts a <see cref="JsonLdContext"/> object to and from JSON.
9-
/// </summary>
10-
/// <seealso cref="JsonConverter" />
11-
public class ContextJsonConverter : JsonConverter<JsonLdContext>
12-
{
13-
/// <inheritdoc />
14-
public override JsonLdContext ReadJson(JsonReader reader, Type objectType, JsonLdContext? existingValue, bool hasExistingValue, JsonSerializer serializer)
15-
{
16-
if (reader is null)
17-
{
18-
throw new ArgumentNullException(nameof(reader));
19-
}
20-
21-
if (objectType is null)
22-
{
23-
throw new ArgumentNullException(nameof(objectType));
24-
}
25-
26-
if (serializer is null)
27-
{
28-
throw new ArgumentNullException(nameof(serializer));
29-
}
30-
31-
var context = hasExistingValue ? existingValue! : new JsonLdContext();
32-
33-
string? name;
34-
string? language;
35-
if (reader.TokenType == JsonToken.String)
36-
{
37-
name = (string?)reader.Value;
38-
language = null;
39-
}
40-
else
41-
{
42-
var o = JObject.Load(reader);
43-
44-
var nameProperty = o.Property("name", StringComparison.OrdinalIgnoreCase);
45-
name = nameProperty?.Value?.ToString() ?? "https://schema.org";
46-
47-
var languageProperty = o.Property("@language", StringComparison.OrdinalIgnoreCase);
48-
language = languageProperty?.Value?.ToString();
49-
}
50-
51-
context.Name = name;
52-
context.Language = language;
53-
return context;
54-
}
55-
56-
/// <inheritdoc />
57-
public override void WriteJson(JsonWriter writer, JsonLdContext? value, JsonSerializer serializer)
58-
{
59-
if (writer is null)
60-
{
61-
throw new ArgumentNullException(nameof(writer));
62-
}
63-
64-
if (value is null)
65-
{
66-
throw new ArgumentNullException(nameof(value));
67-
}
68-
69-
if (serializer is null)
70-
{
71-
throw new ArgumentNullException(nameof(serializer));
72-
}
73-
74-
if (string.IsNullOrWhiteSpace(value.Language))
75-
{
76-
writer.WriteValue(value.Name);
77-
}
78-
else
79-
{
80-
writer.WriteStartObject();
81-
writer.WritePropertyName("name");
82-
writer.WriteValue(value.Name);
83-
writer.WritePropertyName("@language");
84-
writer.WriteValue(value.Language);
85-
writer.WriteEndObject();
86-
}
87-
}
88-
}
89-
}
1+
namespace Schema.NET
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
using Newtonsoft.Json.Linq;
6+
7+
/// <summary>
8+
/// Converts a <see cref="JsonLdContext"/> object to and from JSON.
9+
/// </summary>
10+
/// <seealso cref="JsonConverter" />
11+
public class ContextJsonConverter : JsonConverter<JsonLdContext>
12+
{
13+
/// <inheritdoc />
14+
public override JsonLdContext ReadJson(JsonReader reader, Type objectType, JsonLdContext? existingValue, bool hasExistingValue, JsonSerializer serializer)
15+
{
16+
if (reader is null)
17+
{
18+
throw new ArgumentNullException(nameof(reader));
19+
}
20+
21+
if (objectType is null)
22+
{
23+
throw new ArgumentNullException(nameof(objectType));
24+
}
25+
26+
if (serializer is null)
27+
{
28+
throw new ArgumentNullException(nameof(serializer));
29+
}
30+
31+
var context = hasExistingValue ? existingValue! : new JsonLdContext();
32+
33+
string? name;
34+
string? language;
35+
if (reader.TokenType == JsonToken.String)
36+
{
37+
name = (string?)reader.Value;
38+
language = null;
39+
}
40+
else
41+
{
42+
var o = JObject.Load(reader);
43+
44+
var nameProperty = o.Property("name", StringComparison.OrdinalIgnoreCase);
45+
name = nameProperty?.Value?.ToString() ?? "https://schema.org";
46+
47+
var languageProperty = o.Property("@language", StringComparison.OrdinalIgnoreCase);
48+
language = languageProperty?.Value?.ToString();
49+
}
50+
51+
context.Name = name;
52+
context.Language = language;
53+
return context;
54+
}
55+
56+
/// <inheritdoc />
57+
public override void WriteJson(JsonWriter writer, JsonLdContext? value, JsonSerializer serializer)
58+
{
59+
if (writer is null)
60+
{
61+
throw new ArgumentNullException(nameof(writer));
62+
}
63+
64+
if (value is null)
65+
{
66+
throw new ArgumentNullException(nameof(value));
67+
}
68+
69+
if (serializer is null)
70+
{
71+
throw new ArgumentNullException(nameof(serializer));
72+
}
73+
74+
if (string.IsNullOrWhiteSpace(value.Language))
75+
{
76+
writer.WriteValue(value.Name);
77+
}
78+
else
79+
{
80+
writer.WriteStartObject();
81+
writer.WritePropertyName("name");
82+
writer.WriteValue(value.Name);
83+
writer.WritePropertyName("@language");
84+
writer.WriteValue(value.Language);
85+
writer.WriteEndObject();
86+
}
87+
}
88+
}
89+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)