Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
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
27 changes: 27 additions & 0 deletions src/System.Text.Json/ref/System.Text.Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

namespace System.Text.Json
{
public sealed partial class JsonBoolean : System.Text.Json.JsonNode, System.IEquatable<System.Text.Json.JsonBoolean>
{
public JsonBoolean() { }
public JsonBoolean(bool value) { }
public bool Value { get { throw null; } set { } }
public override bool Equals(object obj) { throw null; }
public bool Equals(System.Text.Json.JsonBoolean other) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Text.Json.JsonBoolean left, System.Text.Json.JsonBoolean right) { throw null; }
public static implicit operator System.Text.Json.JsonBoolean (bool value) { throw null; }
public static bool operator !=(System.Text.Json.JsonBoolean left, System.Text.Json.JsonBoolean right) { throw null; }
public override string ToString() { throw null; }
}
public enum JsonCommentHandling : byte
{
Disallow = (byte)0,
Expand Down Expand Up @@ -308,6 +321,20 @@ public JsonSerializerOptions() { }
public bool WriteIndented { get { throw null; } set { } }
public System.Text.Json.Serialization.JsonConverter GetConverter(System.Type typeToConvert) { throw null; }
}
public sealed partial class JsonString : System.Text.Json.JsonNode, System.IEquatable<System.Text.Json.JsonString>
{
public JsonString() { }
public JsonString(System.ReadOnlySpan<char> value) { }
public JsonString(string value) { }
public string Value { get { throw null; } set { } }
public override bool Equals(object obj) { throw null; }
public bool Equals(System.Text.Json.JsonString other) { throw null; }
public override int GetHashCode() { throw null; }
public static bool operator ==(System.Text.Json.JsonString left, System.Text.Json.JsonString right) { throw null; }
public static implicit operator System.Text.Json.JsonString (string value) { throw null; }
public static bool operator !=(System.Text.Json.JsonString left, System.Text.Json.JsonString right) { throw null; }
public override string ToString() { throw null; }
}
public enum JsonTokenType : byte
{
None = (byte)0,
Expand Down
4 changes: 3 additions & 1 deletion src/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@
<Reference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
<ItemGroup>
<Compile Include="System\Text\Json\Node\JsonBoolean.cs" />
<Compile Include="System\Text\Json\Node\JsonNode.cs" />
<Compile Include="System\Text\Json\Node\JsonNumber.cs" />
<Compile Include="System\Text\Json\Node\JsonNumber.cs" />
<Compile Include="System\Text\Json\Node\JsonString.cs" />
</ItemGroup>
Comment thread
kasiabulat marked this conversation as resolved.
</Project>
98 changes: 98 additions & 0 deletions src/System.Text.Json/src/System/Text/Json/Node/JsonBoolean.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Text.Json
{
/// <summary>
/// Represents a boolean JSON value.
/// </summary>
public sealed class JsonBoolean : JsonNode, IEquatable<JsonBoolean>
{
/// <summary>
/// Initializes a new instance of the <see cref="JsonBoolean"/> class representing the value <see langword="false"/>.
/// </summary>
public JsonBoolean() => Value = false;

/// <summary>
/// Initializes a new instance of the <see cref="JsonBoolean"/> class representing a specified value.
/// </summary>
public JsonBoolean(bool value) => Value = value;

/// <summary>
/// Gets or sets the boolean value represented by the instance.
/// </summary>
public bool Value { get; set; }

/// <summary>
/// Converts the value represented by the instance to the string in JSON format.
/// </summary>
/// <returns>The string representation of the value of this instance.</returns>
public override string ToString() => Value ? "true" : "false";

/// <summary>
/// Converts a <see cref="bool"/> to a <see cref="JsonBoolean"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonBoolean(bool value) => new JsonBoolean(value);
Comment thread
kasiabulat marked this conversation as resolved.

/// <summary>
/// Compares <paramref name="obj"/> to the value of this instance.
/// </summary>
/// <param name="obj">The object to compare against.</param>
/// <returns>
/// <see langword="true"/> if the boolean value of this instance matches <paramref name="obj"/>,
/// <see langword="false"/> otherwise.
/// </returns>
public override bool Equals(object obj) => obj is JsonBoolean jsonBoolean && Equals(jsonBoolean);

/// <summary>
/// Calculates a hash code of this instance.
/// </summary>
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode() => Value.GetHashCode();

/// <summary>
/// Compares other JSON boolean to the value of this instance.
/// </summary>
/// <param name="other">The JSON boolean to compare against.</param>
/// <returns>
/// <see langword="true"/> if the boolean value of this instance matches <paramref name="other"/>,
/// <see langword="false"/> otherwise.
/// </returns>
public bool Equals(JsonBoolean other) => !(other is null) && Value == other.Value;

/// <summary>
/// Compares values of two JSON booleans.
/// </summary>
/// <param name="left">The JSON boolean to compare.</param>
/// <param name="right">The JSON boolean to compare.</param>
/// <returns>
/// <see langword="true"/> if values of instances match,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator ==(JsonBoolean left, JsonBoolean right)
{
// Test "right" first to allow branch elimination when inlined for null checks (== null)
// so it can become a simple test
if (right is null)
Comment thread
kasiabulat marked this conversation as resolved.
{
// return true/false not the test result https://github.com/dotnet/coreclr/issues/914
return (left is null) ? true : false;
}

return right.Equals(left);
}

/// <summary>
/// Compares values of two JSON booleans.
/// </summary>
/// <param name="left">The JSON boolean to compare.</param>
/// <param name="right">The JSON boolean to compare.</param>
/// <returns>
/// <see langword="true"/> if values of instances do not match,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator !=(JsonBoolean left, JsonBoolean right) => !(left == right);
}
}
117 changes: 117 additions & 0 deletions src/System.Text.Json/src/System/Text/Json/Node/JsonString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System.Text.Json
{
/// <summary>
/// Represents a text JSON value.
/// </summary>
public sealed class JsonString : JsonNode, IEquatable<JsonString>
{
private string _value;

/// <summary>
/// Initializes a new instance of the <see cref="JsonString"/> class representing the empty value.
/// </summary>
public JsonString() => Value = string.Empty;

/// <summary>
/// Initializes a new instance of the <see cref="JsonString"/> class representing a specified value.
/// </summary>
/// <param name="value">The value to represent as a JSON string.</param>
/// <exception cref="ArgumentNullException">
/// Provided value is null.
/// </exception>
public JsonString(string value) => Value = value;
Comment thread
kasiabulat marked this conversation as resolved.
Comment thread
kasiabulat marked this conversation as resolved.

/// <summary>
/// Initializes a new instance of the <see cref="JsonString"/> class representing a specified value.
/// </summary>
/// <param name="value">The value to represent as a JSON string.</param>
public JsonString(ReadOnlySpan<char> value) => Value = value.ToString();

/// <summary>
/// Gets or sets the text value represented by the instance.
/// </summary>
/// <exception cref="ArgumentNullException">
/// Provided value is null.
/// </exception>
public string Value
{
get => _value;
set => _value = value ?? throw new ArgumentNullException();
Comment thread
kasiabulat marked this conversation as resolved.
}

/// <summary>
/// Returns the text value represented by the instance.
/// </summary>
/// <returns>The value represented by this instance.</returns>
public override string ToString() => _value;

/// <summary>
/// Converts a <see cref="string"/> to a <see cref="JsonString"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonString(string value) => new JsonString(value);

/// <summary>
/// Compares <paramref name="obj"/> to the value of this instance.
/// </summary>
/// <param name="obj">The object to compare against.</param>
/// <returns>
/// <see langword="true"/> if the text value of this instance matches <paramref name="obj"/>,
/// <see langword="false"/> otherwise.
/// </returns>
public override bool Equals(object obj) => obj is JsonString jsonString && Equals(jsonString);

/// <summary>
/// Calculates a hash code of this instance.
/// </summary>
/// <returns>A hash code for this instance.</returns>
public override int GetHashCode() => Value.GetHashCode();

/// <summary>
/// Compares other JSON string to the value of this instance.
/// </summary>
/// <param name="other">The JSON string to compare against.</param>
/// <returns>
/// <see langword="true"/> if the text value of this instance matches <paramref name="other"/>,
/// <see langword="false"/> otherwise.
/// </returns>
public bool Equals(JsonString other) => !(other is null) && Value == other.Value;
Comment thread
kasiabulat marked this conversation as resolved.

/// <summary>
/// Compares values of two JSON strings.
/// </summary>
/// <param name="left">The JSON string to compare.</param>
/// <param name="right">The JSON string to compare.</param>
/// <returns>
/// <see langword="true"/> if values of instances match,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator ==(JsonString left, JsonString right)
{
// Test "right" first to allow branch elimination when inlined for null checks (== null)
// so it can become a simple test
if (right is null)
{
// return true/false not the test result https://github.com/dotnet/coreclr/issues/914
return (left is null) ? true : false;
}

return right.Equals(left);
}

/// <summary>
/// Compares values of two JSON strings.
/// </summary>
/// <param name="left">The JSON string to compare.</param>
/// <param name="right">The JSON string to compare.</param>
/// <returns>
/// <see langword="true"/> if values of instances do not match,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator !=(JsonString left, JsonString right) => !(left == right);
}
}
Loading