- Notifications
You must be signed in to change notification settings - Fork311
Add ToString() to SqlJson#3427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
7c4e0ff
b30375a
75f87e6
2a2bd10
4ceb419
c0791a8
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -132,7 +132,12 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false | ||
csharp_space_between_parentheses = false | ||
csharp_space_between_square_brackets = false | ||
# Analyzers | ||
dotnet_code_quality.ca1802.api_surface = private, internal | ||
# CA2000: Dispose objects before losing scope | ||
dotnet_diagnostic.CA2000.severity = suggestion | ||
paulmedynski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
# CA1063: Implement IDisposable Correctly | ||
dotnet_diagnostic.CA1063.severity = silent | ||
@@ -143,6 +148,10 @@ dotnet_diagnostic.CA2100.severity = silent | ||
# CA1416: Validate platform compatibility | ||
dotnet_diagnostic.CA1416.severity = silent | ||
dotnet_code_quality.CA2100.excluded_type_names_with_derived_types = Microsoft.Data.SqlClient.ManualTesting.Tests.* | ||
dotnet_diagnostic.xUnit1031.severity=none | ||
dotnet_diagnostic.xUnit1030.severity=none | ||
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] | ||
indent_size = 2 | ||
@@ -163,13 +172,3 @@ indent_size = 2 | ||
end_of_line = lf | ||
[*.{cmd, bat}] | ||
end_of_line = crlf | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<docs> | ||
<members name="SqlJson"> | ||
<SqlJson> | ||
<summary>Represents the JSON datatype in SQL Server.</summary> | ||
</SqlJson> | ||
<ctor1> | ||
<summary> | ||
Construct a new instance of the SqlJson class which represents a null | ||
JSON value. | ||
</summary> | ||
</ctor1> | ||
<ctor2> | ||
<summary> | ||
Construct a new instance of the SqlJson class with a serialized JSON | ||
<see cref="string"/>. The string is validated by parsing it with | ||
<see cref="System.Text.Json.JsonDocument"/>. | ||
</summary> | ||
<param name="jsonString"> | ||
The serialized JSON string to use, or null. | ||
</param> | ||
<throw> | ||
<exception cref="System.Text.Json.JsonException"> | ||
If the given string is not valid JSON. | ||
</exception> | ||
</throw> | ||
</ctor2> | ||
<ctor3> | ||
<summary> | ||
Construct a new instance of the SqlJson class with a | ||
<see cref="System.Text.Json.JsonDocument"/>. The serialized JSON string | ||
from the document is saved. | ||
</summary> | ||
<param name="jsonDoc"> | ||
The document to use, or null. | ||
</param> | ||
<throw> | ||
<exception cref="System.ObjectDisposedException"> | ||
If the given document has been disposed of. | ||
</exception> | ||
</throw> | ||
</ctor3> | ||
<IsNull> | ||
<inheritdoc/> | ||
</IsNull> | ||
<Null> | ||
<summary> | ||
Represents a null instance of the <see cref="SqlJson"/> type. This | ||
instance is equivalent to calling the parameterless constructor, or | ||
calling the other constructors with a null value. | ||
</summary> | ||
</Null> | ||
<Value> | ||
<summary> | ||
Gets the serialized JSON string of this <see cref="SqlJson" /> instance. | ||
</summary> | ||
<throw> | ||
<exception cref="System.Data.SqlTypes.SqlNullValueException"> | ||
If the JSON value is null. | ||
</exception> | ||
</throw> | ||
</Value> | ||
<ToString> | ||
<summary> | ||
Returns the serialized JSON string, or null. | ||
</summary> | ||
</ToString> | ||
</members> | ||
</docs> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,62 +2,63 @@ | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System.Data.SqlTypes; | ||
#if NET | ||
using System.Diagnostics.CodeAnalysis; | ||
#endif | ||
using System.Text.Json; | ||
#nullable enable | ||
namespace Microsoft.Data.SqlTypes | ||
{ | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/SqlJson/*' /> | ||
public class SqlJson : INullable | ||
{ | ||
paulmedynski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// Our serialized JSON string, or null. | ||
private readonly string? _jsonString = null; | ||
paulmedynski marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/ctor1/*' /> | ||
public SqlJson() | ||
{ | ||
} | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/ctor2/*' /> | ||
#if NET | ||
public SqlJson([StringSyntax(StringSyntaxAttribute.Json)] string? jsonString) | ||
#else | ||
public SqlJson(string? jsonString) | ||
#endif | ||
{ | ||
if (jsonString == null) | ||
{ | ||
return; | ||
} | ||
// Ask JsonDocument to parse it for validity, or throw. | ||
// | ||
// Note that we do not support trailing commas or comments in the | ||
// JSON. | ||
// | ||
JsonDocument.Parse(jsonString).Dispose(); | ||
_jsonString = jsonString; | ||
} | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/ctor3/*' /> | ||
public SqlJson(JsonDocument? jsonDoc) | ||
{ | ||
if (jsonDoc == null) | ||
{ | ||
return; | ||
} | ||
// Save the serialized JSON string from the document, or throw. | ||
_jsonString = jsonDoc.RootElement.GetRawText(); | ||
} | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/IsNull/*' /> | ||
public bool IsNull =>_jsonString is null; | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/Null/*' /> | ||
public static SqlJson Null => new(); | ||
@@ -71,33 +72,15 @@ public string Value | ||
{ | ||
throw new SqlNullValueException(); | ||
} | ||
return _jsonString!; | ||
} | ||
} | ||
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlTypes/SqlJson.xml' path='docs/members[@name="SqlJson"]/ToString/*' /> | ||
public override string? ToString() | ||
cheenamalhotra marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
{ | ||
return _jsonString; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.