Skip to content

Commit

Permalink
Strengthen assertions in the nested JsonTypeInfo accessors.
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Feb 8, 2023
1 parent 0129a36 commit 09f8062
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public abstract class JsonPropertyInfo
internal static readonly JsonPropertyInfo s_missingProperty = GetPropertyPlaceholder();

internal JsonTypeInfo? ParentTypeInfo { get; private set; }
private JsonTypeInfo? _jsonTypeInfo;

/// <summary>
/// Converter after applying CustomConverter (i.e. JsonConverterAttribute)
Expand Down Expand Up @@ -803,6 +802,15 @@ internal JsonTypeInfo JsonTypeInfo
}
}

private JsonTypeInfo? _jsonTypeInfo;

/// <summary>
/// Returns true if <see cref="JsonTypeInfo"/> has been configured.
/// This might be false even if <see cref="IsConfigured"/> is true
/// in cases of recursive types or <see cref="IsIgnored"/> is true.
/// </summary>
internal bool IsPropertyTypeInfoConfigured => _jsonTypeInfo?.IsConfigured == true;

/// <summary>
/// Property was marked JsonIgnoreCondition.Always and also hasn't been configured by the user.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,12 @@ private void DetermineIsCompatibleWithCurrentOptions()
{
Debug.Assert(property.IsConfigured);

if (property.IsIgnored)
if (!property.IsPropertyTypeInfoConfigured)
{
// Either an ignored property or property is part of a cycle.
// In both cases we can ignore these instances.
continue;
}

if (!property.JsonTypeInfo.IsCompatibleWithCurrentOptions)
{
Expand Down

0 comments on commit 09f8062

Please sign in to comment.