Skip to content

Commit

Permalink
Add copy constructor to reset "Lazy"
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Mar 21, 2023
1 parent f4f2e29 commit 938f272
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,22 @@ public sealed record SymbolicValue
public static readonly SymbolicValue False = NotNull.WithConstraint(BoolConstraint.False);

// SymbolicValue can have only one constraint instance of specific type at a time
private ImmutableDictionary<Type, SymbolicConstraint> Constraints { get; init; } = ImmutableDictionary<Type, SymbolicConstraint>.Empty;
private ImmutableDictionary<Type, SymbolicConstraint> Constraints { get; init; }

public IEnumerable<SymbolicConstraint> AllConstraints =>
Constraints.Values;

public SymbolicValue()
public SymbolicValue() : this(null)
{
hashCode = new(() => HashCode.DictionaryContentHash(Constraints), LazyThreadSafetyMode.ExecutionAndPublication);
}

private SymbolicValue(SymbolicValue other)
{
Constraints = other?.Constraints ?? ImmutableDictionary<Type, SymbolicConstraint>.Empty;
hashCode = new(() => HashCode.DictionaryContentHash(Constraints), LazyThreadSafetyMode.ExecutionAndPublication);
}

public override string ToString() =>
SerializeConstraints();

Expand Down

0 comments on commit 938f272

Please sign in to comment.