Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8013865
Json prototype (#1)
kasiabulat Jul 17, 2019
0f7df28
Json prototype - transformation API (#2)
kasiabulat Jul 19, 2019
6cd2efb
Json prototype (#1)
kasiabulat Jul 17, 2019
409e575
Json prototype - transformation API (#2)
kasiabulat Jul 19, 2019
25109c3
Merge branch 'master' of https://github.com/kasiabulat/corefx
kasiabulat Jul 29, 2019
9dcfc4b
JsonNumber implementation and tests (#3)
kasiabulat Jul 30, 2019
38af6d9
Merge remote-tracking branch 'upstream/master'
kasiabulat Jul 30, 2019
08f4734
all unimplemented classes and methods with accompanying tests removed
kasiabulat Jul 30, 2019
63ff329
First part of documentation added
kasiabulat Jul 30, 2019
0e0fb7c
documentation completed
kasiabulat Jul 31, 2019
47666ce
missing exceptions added
kasiabulat Jul 31, 2019
d856681
JsonElement changes removed
kasiabulat Jul 31, 2019
22e6558
part of the review comments included
kasiabulat Aug 1, 2019
04441f1
work on review comments
kasiabulat Aug 1, 2019
30c5dd0
code refactor
kasiabulat Aug 5, 2019
8f3e510
more decimal tests added using MemberData
kasiabulat Aug 5, 2019
c6ab148
more decimal tests added using MemberData
kasiabulat Aug 5, 2019
259590b
more test cases added
kasiabulat Aug 5, 2019
c4d6ef2
equals summary adjusted, equals tests added
kasiabulat Aug 5, 2019
01c230f
more Equals tests added, GetHashCode tests added, minor changes
kasiabulat Aug 6, 2019
392142a
scientifing notation support added, rational numbers tests fixes
kasiabulat Aug 6, 2019
310a5a6
rational overflow tests added
kasiabulat Aug 6, 2019
e03b803
ulong maxvalue tests added to rational types
kasiabulat Aug 6, 2019
95a9401
presision problems fixes
kasiabulat Aug 6, 2019
2bd6871
exception strings fixed
kasiabulat Aug 6, 2019
f0c4814
CI failing fixes (hopefully), review comments included
kasiabulat Aug 7, 2019
c22b36d
missing == tests added to achieve 100% branch coverage
kasiabulat Aug 7, 2019
7dfc891
review comments included
kasiabulat Aug 8, 2019
07746d8
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat Aug 8, 2019
d479fa7
Merge remote-tracking branch 'upstream/master' into kasiabulat/json-n…
kasiabulat Aug 8, 2019
ab1401a
trailing whitespaces fixes
kasiabulat Aug 8, 2019
217bade
equals comments added
kasiabulat Aug 8, 2019
40a6649
equals object refactored to call quals json number
kasiabulat Aug 8, 2019
af4aed3
Merge conflicts resolved
kasiabulat Aug 8, 2019
f534415
merge fix
kasiabulat Aug 8, 2019
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
Prev Previous commit
Next Next commit
documentation completed
  • Loading branch information
kasiabulat committed Jul 31, 2019
commit 0e0fb7c8f8f7178787ad3acbbc947f5d2c2fb9b1
291 changes: 270 additions & 21 deletions src/System.Text.Json/src/System/Text/Json/Node/JsonNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,154 @@ public partial class JsonNumber : JsonNode, IEquatable<JsonNumber>
/// </returns>
public bool TryGetByte(out byte value) => byte.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Int16 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Int16 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetInt16(out short value) => short.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Int32 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Int32 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetInt32(out int value) => int.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Int64 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Int64 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetInt64(out long value) => long.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Single equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Single value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetSingle(out float value) => float.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Double equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Double value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetDouble(out double value) => double.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its SByte equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the SByte value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
[CLSCompliant(false)]
public bool TryGetSByte(out sbyte value) => sbyte.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its UInt16 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the UInt16 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
[CLSCompliant(false)]
public bool TryGetUInt16(out ushort value) => ushort.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its UInt32 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the UInt32 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
[CLSCompliant(false)]
public bool TryGetUInt32(out uint value) => uint.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its UInt64 equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the UInt64 value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
[CLSCompliant(false)]
public bool TryGetUInt64(out ulong value) => ulong.TryParse(_value, out value);

/// <summary>
/// Converts the numeric value of this instance to its Decimal equivalent.
/// A return value indicates whether the conversion succeeded.
/// </summary>
/// <param name="value">
/// When this method returns, contains the Decimal value equivalent of the number contained in this instance,
/// if the conversion succeeded, or zero if the conversion failed.
/// </param>
/// <returns>
/// // <see langword="true"/> if instance was converted successfully;
/// otherwise, <see langword="false"/>
/// </returns>
public bool TryGetDecimal(out decimal value) => decimal.TryParse(_value, out value);


/// <summary>
/// Changes the numeric value of this instance to represent a specified value.
/// </summary>
/// <param name="value">The string representation of a numeric value in a legal JSON number format.</param>
public void SetFormattedValue(string value)
{
if (value == null)
Expand All @@ -284,66 +407,192 @@ public void SetFormattedValue(string value)
_value = value;
}

/// <summary>
/// Changes the numeric value of this instance to represent a specified Byte value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetByte(byte value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Int16 value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetInt16(short value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Int32 value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetInt32(int value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Int64 value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetInt64(long value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Single value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetSingle(float value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Double value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetDouble(double value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified SByte value.
/// </summary>
/// <param name="value">The value to represent.</param>
[CLSCompliant(false)]
public void SetSByte(sbyte value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified UInt16 value.
/// </summary>
/// <param name="value">The value to represent.</param>
[CLSCompliant(false)]
public void SetUInt16(ushort value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified UInt32 value.
/// </summary>
/// <param name="value">The value to represent.</param>
[CLSCompliant(false)]
public void SetUInt32(uint value) => _value = value.ToString();


/// <summary>
/// Changes the numeric value of this instance to represent a specified Uint64 value.
/// </summary>
/// <param name="value">The value to represent.</param>
[CLSCompliant(false)]
public void SetUInt64(ulong value) => _value = value.ToString();

/// <summary>
/// Changes the numeric value of this instance to represent a specified Decimal value.
/// </summary>
/// <param name="value">The value to represent.</param>
public void SetDecimal(decimal value) => _value = value.ToString();

/// <summary>
/// Converts a Byte to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(byte value) => new JsonNumber(value);

public static implicit operator JsonNumber(int value) => new JsonNumber(value);


/// <summary>
/// Converts an Int16 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(short value) => new JsonNumber(value);


/// <summary>
/// Converts an Int32 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(int value) => new JsonNumber(value);

/// <summary>
/// Converts an Int64 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(long value) => new JsonNumber(value);


/// <summary>
/// Converts a Single to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(float value) => new JsonNumber(value);


/// <summary>
/// Converts a Double to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(double value) => new JsonNumber(value);


/// <summary>
/// Converts a SByte to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
[CLSCompliant(false)]
public static implicit operator JsonNumber(sbyte value) => new JsonNumber(value);


/// <summary>
/// Converts a UInt16 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
[CLSCompliant(false)]
public static implicit operator JsonNumber(ushort value) => new JsonNumber(value);


/// <summary>
/// Converts a UInt32 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
[CLSCompliant(false)]
public static implicit operator JsonNumber(uint value) => new JsonNumber(value);


/// <summary>
/// Converts a UInt64 to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
[CLSCompliant(false)]
public static implicit operator JsonNumber(ulong value) => new JsonNumber(value);

/// <summary>
/// Converts a Decimal to a JSON number.
/// </summary>
/// <param name="value">The value to convert.</param>
public static implicit operator JsonNumber(decimal value) => new JsonNumber(value);

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

/// <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 number to the numeric value of this instance.
/// </summary>
/// <param name="other">The JSON number to compare against.</param>
/// <returns>
/// <see langword="true"/> if the numeric value of this instance matches <paramref name="other"/>,
/// <see langword="false"/> otherwise.
/// </returns>
public bool Equals(JsonNumber other) => _value == other._value;

/// <summary>
/// Compares numeric values of two JSON numbers.
/// </summary>
/// <param name="left">The JSON number to compare.</param>
/// <param name="right">The JSON number to compare.</param>
/// <returns>
/// <see langword="true"/> if the numeric value of instances matches,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator ==(JsonNumber left, JsonNumber right) => left._value == right._value;


/// <summary>
/// Compares numeric values of two JSON numbers.
/// </summary>
/// <param name="left">The JSON number to compare.</param>
/// <param name="right">The JSON number to compare.</param>
/// <returns>
/// <see langword="true"/> if the numeric value of instances does not match,
/// <see langword="false"/> otherwise.
/// </returns>
public static bool operator !=(JsonNumber left, JsonNumber right) => left._value != right._value;
}
}