Skip to content

Commit

Permalink
Use a builder instead of ImmutableDictionary in JSON models
Browse files Browse the repository at this point in the history
This works around JamesNK/Newtonsoft.Json#652 by avoiding the direct use
of immutable types in the serialization process. The result remains
efficient because the builder class caches the last returned immutable
instance, and will continue returning the same instance as long as no
changes are made to the builder.

Fixes DotNetAnalyzers#1359
  • Loading branch information
sharwell committed Sep 19, 2015
1 parent be984ba commit 691b9f8
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class DocumentationSettings
/// This is the backing field for the <see cref="Variables"/> property.
/// </summary>
[JsonProperty("variables", DefaultValueHandling = DefaultValueHandling.Ignore)]
private ImmutableDictionary<string, string> variables;
private ImmutableDictionary<string, string>.Builder variables;

/// <summary>
/// This is the backing field for the <see cref="XmlHeader"/> property.
Expand Down Expand Up @@ -82,7 +82,7 @@ protected internal DocumentationSettings()
{
this.companyName = DefaultCompanyName;
this.copyrightText = DefaultCopyrightText;
this.variables = ImmutableDictionary<string, string>.Empty;
this.variables = ImmutableDictionary<string, string>.Empty.ToBuilder();
this.xmlHeader = true;

this.documentExposedElements = true;
Expand Down Expand Up @@ -138,7 +138,7 @@ public string CopyrightText
{
get
{
return this.variables;
return this.variables.ToImmutable();
}
}

Expand Down

0 comments on commit 691b9f8

Please sign in to comment.