Skip to content

Commit a0d7cfd

Browse files
committed
Use explicit conversions where JsonValue is lossy
1 parent 6c6f0ef commit a0d7cfd

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.Test/Helpers/DiagnosticVerifier.Helper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ protected virtual Solution CreateSolution(ProjectId projectId, string language)
166166
}
167167
else
168168
{
169-
JsonObject indentationObject = JsonReader.Parse(indentationSettings);
170-
JsonObject settingsObject = JsonReader.Parse(settings);
169+
JsonObject indentationObject = JsonReader.Parse(indentationSettings).AsJsonObject;
170+
JsonObject settingsObject = JsonReader.Parse(settings).AsJsonObject;
171171
JsonObject mergedSettings = MergeJsonObjects(settingsObject, indentationObject);
172172
using (var writer = new JsonWriter(pretty: true))
173173
{

StyleCop.Analyzers/StyleCop.Analyzers/LightJson/JsonValue.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ public static implicit operator JsonValue(DateTime? value)
583583
/// Converts the given JsonValue into an Int.
584584
/// </summary>
585585
/// <param name="jsonValue">The JsonValue to be converted.</param>
586-
public static implicit operator int(JsonValue jsonValue)
586+
public static explicit operator int(JsonValue jsonValue)
587587
{
588588
if (jsonValue.IsInteger)
589589
{
@@ -603,7 +603,7 @@ public static implicit operator int(JsonValue jsonValue)
603603
/// Throws System.InvalidCastException when the inner value type of the
604604
/// JsonValue is not the desired type of the conversion.
605605
/// </exception>
606-
public static implicit operator int?(JsonValue jsonValue)
606+
public static explicit operator int?(JsonValue jsonValue)
607607
{
608608
if (jsonValue.IsNull)
609609
{
@@ -619,7 +619,7 @@ public static implicit operator int(JsonValue jsonValue)
619619
/// Converts the given JsonValue into a Bool.
620620
/// </summary>
621621
/// <param name="jsonValue">The JsonValue to be converted.</param>
622-
public static implicit operator bool(JsonValue jsonValue)
622+
public static explicit operator bool(JsonValue jsonValue)
623623
{
624624
if (jsonValue.IsBoolean)
625625
{
@@ -639,7 +639,7 @@ public static implicit operator bool(JsonValue jsonValue)
639639
/// Throws System.InvalidCastException when the inner value type of the
640640
/// JsonValue is not the desired type of the conversion.
641641
/// </exception>
642-
public static implicit operator bool?(JsonValue jsonValue)
642+
public static explicit operator bool?(JsonValue jsonValue)
643643
{
644644
if (jsonValue.IsNull)
645645
{
@@ -655,7 +655,7 @@ public static implicit operator bool(JsonValue jsonValue)
655655
/// Converts the given JsonValue into a Double.
656656
/// </summary>
657657
/// <param name="jsonValue">The JsonValue to be converted.</param>
658-
public static implicit operator double(JsonValue jsonValue)
658+
public static explicit operator double(JsonValue jsonValue)
659659
{
660660
if (jsonValue.IsNumber)
661661
{
@@ -675,7 +675,7 @@ public static implicit operator double(JsonValue jsonValue)
675675
/// Throws System.InvalidCastException when the inner value type of the
676676
/// JsonValue is not the desired type of the conversion.
677677
/// </exception>
678-
public static implicit operator double?(JsonValue jsonValue)
678+
public static explicit operator double?(JsonValue jsonValue)
679679
{
680680
if (jsonValue.IsNull)
681681
{
@@ -691,7 +691,7 @@ public static implicit operator double(JsonValue jsonValue)
691691
/// Converts the given JsonValue into a String.
692692
/// </summary>
693693
/// <param name="jsonValue">The JsonValue to be converted.</param>
694-
public static implicit operator string(JsonValue jsonValue)
694+
public static explicit operator string(JsonValue jsonValue)
695695
{
696696
if (jsonValue.IsString || jsonValue.IsNull)
697697
{
@@ -707,7 +707,7 @@ public static implicit operator string(JsonValue jsonValue)
707707
/// Converts the given JsonValue into a JsonObject.
708708
/// </summary>
709709
/// <param name="jsonValue">The JsonValue to be converted.</param>
710-
public static implicit operator JsonObject(JsonValue jsonValue)
710+
public static explicit operator JsonObject(JsonValue jsonValue)
711711
{
712712
if (jsonValue.IsJsonObject || jsonValue.IsNull)
713713
{
@@ -723,7 +723,7 @@ public static implicit operator JsonObject(JsonValue jsonValue)
723723
/// Converts the given JsonValue into a JsonArray.
724724
/// </summary>
725725
/// <param name="jsonValue">The JsonValue to be converted.</param>
726-
public static implicit operator JsonArray(JsonValue jsonValue)
726+
public static explicit operator JsonArray(JsonValue jsonValue)
727727
{
728728
if (jsonValue.IsJsonArray || jsonValue.IsNull)
729729
{
@@ -739,7 +739,7 @@ public static implicit operator JsonArray(JsonValue jsonValue)
739739
/// Converts the given JsonValue into a DateTime.
740740
/// </summary>
741741
/// <param name="jsonValue">The JsonValue to be converted.</param>
742-
public static implicit operator DateTime(JsonValue jsonValue)
742+
public static explicit operator DateTime(JsonValue jsonValue)
743743
{
744744
var dateTime = jsonValue.AsDateTime;
745745

@@ -757,7 +757,7 @@ public static implicit operator DateTime(JsonValue jsonValue)
757757
/// Converts the given JsonValue into a nullable DateTime.
758758
/// </summary>
759759
/// <param name="jsonValue">The JsonValue to be converted.</param>
760-
public static implicit operator DateTime?(JsonValue jsonValue)
760+
public static explicit operator DateTime?(JsonValue jsonValue)
761761
{
762762
if (jsonValue.IsDateTime || jsonValue.IsNull)
763763
{

0 commit comments

Comments
 (0)