Skip to content
Merged
Changes from all commits
Commits
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 @@ -195,19 +195,27 @@ internal JsonTypeInfo(Type type, JsonConverter converter, JsonSerializerOptions
}

private bool _isConfigured;
private object _configureLock = new object();

internal void EnsureConfigured()
{
if (_isConfigured)
return;

Configure();
lock (_configureLock)
{
if (_isConfigured)
return;

Configure();

_isConfigured = true;
_isConfigured = true;
}
}

internal virtual void Configure()
{
Debug.Assert(Monitor.IsEntered(_configureLock), "Configure called directly, use EnsureConfigured which locks this method");
Copy link
Member

Choose a reason for hiding this comment

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

Since this is virtual, might make sense to add the same to any overrides?

Copy link
Member Author

Choose a reason for hiding this comment

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

they will call base.Configure anyway

Copy link
Member

Choose a reason for hiding this comment

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

OK. That might change in future iterations, but I guess nothing prevents users from overriding the Configure method elsewhere either.

Copy link
Member

Choose a reason for hiding this comment

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

Should the method be changed to protected virtual instead?

JsonConverter converter = PropertyInfoForTypeInfo.ConverterBase;
Debug.Assert(PropertyInfoForTypeInfo.ConverterStrategy == PropertyInfoForTypeInfo.ConverterBase.ConverterStrategy,
$"ConverterStrategy from PropertyInfoForTypeInfo.ConverterStrategy ({PropertyInfoForTypeInfo.ConverterStrategy}) does not match converter's ({PropertyInfoForTypeInfo.ConverterBase.ConverterStrategy})");
Expand Down