Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
305c51c
first pass making JsonData internal
annelo-msft Nov 17, 2022
9e3f2e2
make indexer access entirely dynamic; add tests with newly requested …
annelo-msft Nov 17, 2022
32d1970
removed unused public APIs
annelo-msft Nov 17, 2022
0eff1da
return null for optional properties
annelo-msft Nov 17, 2022
43cd339
dispose JsonDocument
annelo-msft Nov 17, 2022
d394764
nit rewrite for clarity
annelo-msft Nov 18, 2022
d196588
add tests of requirements for 'leaf node' dynamic interface
annelo-msft Nov 18, 2022
be4cc72
add tests of requirements for array dyanmic interface
annelo-msft Nov 19, 2022
4fe4d95
adding tests on object dynamic interface
annelo-msft Nov 19, 2022
7ac745b
some test re-org for clarity; not complete.
annelo-msft Nov 22, 2022
d638359
Merge remote-tracking branch 'upstream/main' into jsondata-experiment…
annelo-msft Dec 2, 2022
cc1de18
Make JsonData public and change namespace
annelo-msft Dec 2, 2022
a2b2fc5
add int equality operator
annelo-msft Dec 2, 2022
eb74ae2
update API
annelo-msft Dec 3, 2022
3f1adb9
add test that only works when access is public
annelo-msft Dec 7, 2022
c4ebd66
Address build break in Experimental perf project
annelo-msft Dec 7, 2022
17f842b
changes to benchmark project
annelo-msft Dec 7, 2022
1766a04
sm refactor: move operators to a separate file before adding many
annelo-msft Dec 9, 2022
fa019d9
Merge remote-tracking branch 'upstream/main' into jsondata-experiment…
annelo-msft Dec 9, 2022
a0ed823
exclude public tests from InternalsVisibleTo test project, and ignore…
annelo-msft Dec 9, 2022
f2864fc
make casts to primitive types implicit
annelo-msft Dec 10, 2022
4f714bb
export API
annelo-msft Dec 10, 2022
b13740f
Merge remote-tracking branch 'upstream/main' into jsondata-experiment…
annelo-msft Dec 12, 2022
1b5df72
pr fb
annelo-msft Dec 12, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,91 +106,39 @@ public readonly partial struct Value
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public bool TryGetValue<T>(out T value) { throw null; }
}
}
namespace Azure.Core
namespace Azure.Core.Dynamic
{
public static partial class BinaryDataExtensions
{
public static dynamic ToDynamic(this System.BinaryData data) { throw null; }
}
[System.Diagnostics.DebuggerDisplayAttribute("{DebuggerDisplay,nq}")]
public partial class JsonData : System.Dynamic.IDynamicMetaObjectProvider, System.IEquatable<Azure.Core.JsonData>
public partial class JsonData : System.Dynamic.IDynamicMetaObjectProvider, System.IEquatable<Azure.Core.Dynamic.JsonData>
{
public JsonData() { }
public JsonData(object? value) { }
public JsonData(object? value, System.Text.Json.JsonSerializerOptions options, System.Type? type = null) { }
public JsonData(System.Text.Json.JsonDocument jsonDocument) { }
public Azure.Core.JsonData this[int arrayIndex] { get { throw null; } set { } }
public Azure.Core.JsonData this[string propertyName] { get { throw null; } set { } }
public System.Collections.Generic.IEnumerable<Azure.Core.JsonData> Items { get { throw null; } }
public System.Text.Json.JsonValueKind Kind { get { throw null; } }
public int Length { get { throw null; } }
public System.Collections.Generic.IEnumerable<string> Properties { get { throw null; } }
public void Add(bool value) { }
public void Add(double value) { }
public void Add(int value) { }
public void Add(long value) { }
public Azure.Core.JsonData Add(object? serializable) { throw null; }
public Azure.Core.JsonData Add(object? serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
public void Add(float value) { }
public void Add(string? value) { }
public Azure.Core.JsonData AddEmptyArray() { throw null; }
public Azure.Core.JsonData AddEmptyObject() { throw null; }
public Azure.Core.JsonData Add<T>(T[] serializable) { throw null; }
public Azure.Core.JsonData Add<T>(T[] serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
public static Azure.Core.JsonData EmptyArray() { throw null; }
public static Azure.Core.JsonData EmptyObject() { throw null; }
public bool Equals(Azure.Core.JsonData other) { throw null; }
internal JsonData() { }
public bool Equals(Azure.Core.Dynamic.JsonData other) { throw null; }
public override bool Equals(object? obj) { throw null; }
public static Azure.Core.JsonData FromBytes(byte[] utf8Json) { throw null; }
public static Azure.Core.JsonData FromBytes(System.ReadOnlyMemory<byte> utf8Json) { throw null; }
public static Azure.Core.JsonData FromObject<T>(T value, System.Text.Json.JsonSerializerOptions? options = null) { throw null; }
public static Azure.Core.JsonData FromStream(System.IO.Stream utf8Json) { throw null; }
public static System.Threading.Tasks.Task<Azure.Core.JsonData> FromStreamAsync(System.IO.Stream utf8JsonStream, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static Azure.Core.JsonData FromString(string json) { throw null; }
public Azure.Core.JsonData? Get(string propertyName) { throw null; }
public override int GetHashCode() { throw null; }
public T Get<T>(string propertyName) { throw null; }
public T Get<T>(string propertyName, System.Text.Json.JsonSerializerOptions options) { throw null; }
public static bool operator ==(Azure.Core.JsonData? left, string? right) { throw null; }
public static bool operator ==(string? left, Azure.Core.JsonData? right) { throw null; }
public static explicit operator bool (Azure.Core.JsonData json) { throw null; }
public static explicit operator double (Azure.Core.JsonData json) { throw null; }
public static explicit operator int (Azure.Core.JsonData json) { throw null; }
public static explicit operator long (Azure.Core.JsonData json) { throw null; }
public static explicit operator bool? (Azure.Core.JsonData json) { throw null; }
public static explicit operator double? (Azure.Core.JsonData json) { throw null; }
public static explicit operator int? (Azure.Core.JsonData json) { throw null; }
public static explicit operator long? (Azure.Core.JsonData json) { throw null; }
public static explicit operator float? (Azure.Core.JsonData json) { throw null; }
public static explicit operator float (Azure.Core.JsonData json) { throw null; }
public static explicit operator string (Azure.Core.JsonData json) { throw null; }
public static implicit operator Azure.Core.JsonData (bool value) { throw null; }
public static implicit operator Azure.Core.JsonData (double value) { throw null; }
public static implicit operator Azure.Core.JsonData (int value) { throw null; }
public static implicit operator Azure.Core.JsonData (long value) { throw null; }
public static implicit operator Azure.Core.JsonData (bool? value) { throw null; }
public static implicit operator Azure.Core.JsonData (double? value) { throw null; }
public static implicit operator Azure.Core.JsonData (int? value) { throw null; }
public static implicit operator Azure.Core.JsonData (long? value) { throw null; }
public static implicit operator Azure.Core.JsonData (float? value) { throw null; }
public static implicit operator Azure.Core.JsonData (float value) { throw null; }
public static implicit operator Azure.Core.JsonData (string? value) { throw null; }
public static bool operator !=(Azure.Core.JsonData? left, string? right) { throw null; }
public static bool operator !=(string? left, Azure.Core.JsonData? right) { throw null; }
public void Set(string propertyName, bool value) { }
public void Set(string propertyName, double value) { }
public void Set(string propertyName, int value) { }
public void Set(string propertyName, long value) { }
public Azure.Core.JsonData Set(string propertyName, object? serializable) { throw null; }
public Azure.Core.JsonData Set(string propertyName, object? serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
public void Set(string propertyName, float value) { }
public void Set(string propertyName, string? value) { }
public Azure.Core.JsonData SetEmptyArray(string propertyName) { throw null; }
public Azure.Core.JsonData SetEmptyObject(string propertyName) { throw null; }
public Azure.Core.JsonData Set<T>(string propertyName, T[] serializable) { throw null; }
public Azure.Core.JsonData Set<T>(string propertyName, T[] serializable, System.Text.Json.JsonSerializerOptions options) { throw null; }
public static bool operator ==(Azure.Core.Dynamic.JsonData? left, int right) { throw null; }
public static bool operator ==(Azure.Core.Dynamic.JsonData? left, string? right) { throw null; }
public static bool operator ==(int left, Azure.Core.Dynamic.JsonData? right) { throw null; }
public static bool operator ==(string? left, Azure.Core.Dynamic.JsonData? right) { throw null; }
public static implicit operator bool (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator double (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator int (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator long (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator bool? (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator double? (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator int? (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator long? (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator float? (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator float (Azure.Core.Dynamic.JsonData json) { throw null; }
public static implicit operator string (Azure.Core.Dynamic.JsonData json) { throw null; }
public static bool operator !=(Azure.Core.Dynamic.JsonData? left, int right) { throw null; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want equality operators for the same set of primitives that we have the casts for?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will be addressed in a follow-up PR. My goal was to merge this to make something available early for CloudMachine to start working with.

public static bool operator !=(Azure.Core.Dynamic.JsonData? left, string? right) { throw null; }
public static bool operator !=(int left, Azure.Core.Dynamic.JsonData? right) { throw null; }
public static bool operator !=(string? left, Azure.Core.Dynamic.JsonData? right) { throw null; }
System.Dynamic.DynamicMetaObject System.Dynamic.IDynamicMetaObjectProvider.GetMetaObject(System.Linq.Expressions.Expression parameter) { throw null; }
public string ToJsonString() { throw null; }
public override string ToString() { throw null; }
public T To<T>() { throw null; }
public T To<T>(System.Text.Json.JsonSerializerOptions options) { throw null; }
public long WriteTo(System.IO.Stream stream) { throw null; }
public System.Threading.Tasks.Task<long> WriteToAsync(System.IO.Stream stream, System.Threading.CancellationToken cancellationToken) { throw null; }
}
}
20 changes: 20 additions & 0 deletions sdk/core/Azure.Core.Experimental/src/BinaryDataExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.Core.Dynamic
{
/// <summary>
/// Extensions to BinaryData.
/// </summary>
public static class BinaryDataExtensions
{
/// <summary>
/// </summary>
public static dynamic ToDynamic(this BinaryData data)
{
return JsonData.Parse(data);
}
}
}
195 changes: 195 additions & 0 deletions sdk/core/Azure.Core.Experimental/src/JsonData.Operators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Dynamic;
using System.Text.Json;

namespace Azure.Core.Dynamic
{
/// <summary>
/// A mutable representation of a JSON value.
/// </summary>
public partial class JsonData : IDynamicMetaObjectProvider, IEquatable<JsonData>
{
/// <summary>
/// Converts the value to a <see cref="bool"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator bool(JsonData json) => json.GetBoolean();

/// <summary>
/// Converts the value to a <see cref="int"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator int(JsonData json) => json.GetInt32();

/// <summary>
/// Converts the value to a <see cref="long"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator long(JsonData json) => json.GetLong();

/// <summary>
/// Converts the value to a <see cref="string"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator string?(JsonData json) => json.GetString();

/// <summary>
/// Converts the value to a <see cref="float"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator float(JsonData json) => json.GetFloat();

/// <summary>
/// Converts the value to a <see cref="double"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator double(JsonData json) => json.GetDouble();

/// <summary>
/// Converts the value to a <see cref="bool"/>
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator bool?(JsonData json) => json.Kind == JsonValueKind.Null ? null : json.GetBoolean();

/// <summary>
/// Converts the value to a <see cref="int"/> or null.
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator int?(JsonData json) => json.Kind == JsonValueKind.Null ? null : json.GetInt32();

/// <summary>
/// Converts the value to a <see cref="long"/> or null.
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator long?(JsonData json) => json.Kind == JsonValueKind.Null ? null : json.GetLong();

/// <summary>
/// Converts the value to a <see cref="float"/> or null.
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator float?(JsonData json) => json.Kind == JsonValueKind.Null ? null : json.GetFloat();

/// <summary>
/// Converts the value to a <see cref="double"/> or null.
/// </summary>
/// <param name="json">The value to convert.</param>
public static implicit operator double?(JsonData json) => json.Kind == JsonValueKind.Null ? null : json.GetDouble();

/// <summary>
/// Returns true if a <see cref="JsonData"/> has the same value as a given string,
/// and false otherwise.
/// </summary>
/// <param name="left">The <see cref="JsonData"/> to compare.</param>
/// <param name="right">The <see cref="string"/> to compare.</param>
/// <returns>True if the given JsonData represents the given string, and false otherwise.</returns>
public static bool operator ==(JsonData? left, string? right)
{
if (left is null && right is null)
{
return true;
}

if (left is null || right is null)
{
return false;
}

return left.Kind == JsonValueKind.String && ((string?)left._value) == right;
}

/// <summary>
/// Returns false if a <see cref="JsonData"/> has the same value as a given string,
/// and true otherwise.
/// </summary>
/// <param name="left">The <see cref="JsonData"/> to compare.</param>
/// <param name="right">The <see cref="string"/> to compare.</param>
/// <returns>False if the given JsonData represents the given string, and false otherwise</returns>
public static bool operator !=(JsonData? left, string? right) => !(left == right);

/// <summary>
/// Returns true if a <see cref="JsonData"/> has the same value as a given string,
/// and false otherwise.
/// </summary>
/// <param name="left">The <see cref="string"/> to compare.</param>
/// <param name="right">The <see cref="JsonData"/> to compare.</param>
/// <returns>True if the given JsonData represents the given string, and false otherwise.</returns>
public static bool operator ==(string? left, JsonData? right)
{
if (left is null && right is null)
{
return true;
}

if (left is null || right is null)
{
return false;
}

return right.Kind == JsonValueKind.String && ((string?)right._value) == left;
}

/// <summary>
/// Returns false if a <see cref="JsonData"/> has the same value as a given string,
/// and true otherwise.
/// </summary>
/// <param name="left">The <see cref="string"/> to compare.</param>
/// <param name="right">The <see cref="JsonData"/> to compare.</param>
/// <returns>False if the given JsonData represents the given string, and false otherwise</returns>
public static bool operator !=(string? left, JsonData? right) => !(left == right);

/// <summary>
/// Returns true if a <see cref="JsonData"/> has the same value as a given int,
/// and false otherwise.
/// </summary>
/// <param name="left">The <see cref="JsonData"/> to compare.</param>
/// <param name="right">The <see cref="int"/> to compare.</param>
/// <returns>True if the given JsonData represents the given int, and false otherwise.</returns>
public static bool operator ==(JsonData? left, int right)
{
if (left is null)
{
return false;
}

return left.Kind == JsonValueKind.Number && ((int)left) == right;
}

/// <summary>
/// Returns false if a <see cref="JsonData"/> has the same value as a given int,
/// and true otherwise.
/// </summary>
/// <param name="left">The <see cref="JsonData"/> to compare.</param>
/// <param name="right">The <see cref="int"/> to compare.</param>
/// <returns>False if the given JsonData represents the given string, and false otherwise</returns>
public static bool operator !=(JsonData? left, int right) => !(left == right);

/// <summary>
/// Returns true if a <see cref="JsonData"/> has the same value as a given int,
/// and false otherwise.
/// </summary>
/// <param name="left">The <see cref="int"/> to compare.</param>
/// <param name="right">The <see cref="JsonData"/> to compare.</param>
/// <returns>True if the given JsonData represents the given int, and false otherwise.</returns>
public static bool operator ==(int left, JsonData? right)
{
if (right is null)
{
return false;
}

return right.Kind == JsonValueKind.Number && ((int)right) == left;
}

/// <summary>
/// Returns false if a <see cref="JsonData"/> has the same value as a given int,
/// and true otherwise.
/// </summary>
/// <param name="left">The <see cref="int"/> to compare.</param>
/// <param name="right">The <see cref="JsonData"/> to compare.</param>
/// <returns>False if the given JsonData represents the given int, and false otherwise</returns>
public static bool operator !=(int left, JsonData? right) => !(left == right);
}
}
Loading