pulumi/sdk/dotnet/Pulumi.Automation/ProjectTemplateConfigValue.cs
Anton Tayanovskyy fc8262bad0
Avoid overriding dotnet proj settings accidentally (#6670)
* Add failing test

* Guard against overrding project settings accidentally

* Throw exception in case of conflct

* Update sdk/dotnet/Pulumi.Automation/DictionaryContentsComparer.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectRuntime.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectTemplateConfigValue.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectTemplate.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectRuntimeOptions.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectBackend.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Update sdk/dotnet/Pulumi.Automation/ProjectSettings.cs

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>

* Reduce nesting

* Make the new exception public

* Introduce a CHANGELOG entry since we add to pub API

* Stricter check before throwing

* Address PR feedback, round 1

* Use Reference.Equals check

* Move DictionaryContentsComparer out of top-level

Co-authored-by: Komal Ali <komal@pulumi.com>
Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
2021-04-01 15:27:24 -04:00

50 lines
1.5 KiB
C#

// Copyright 2016-2021, Pulumi Corporation
using System;
using System.Collections.Generic;
namespace Pulumi.Automation
{
/// <summary>
/// A placeholder config value for a project template.
/// </summary>
public class ProjectTemplateConfigValue
{
internal static IEqualityComparer<ProjectTemplateConfigValue> Comparer { get; } = new ProjectTemplateConfigValueComparer();
public string? Description { get; set; }
public string? Default { get; set; }
public bool? Secret { get; set; }
private sealed class ProjectTemplateConfigValueComparer : IEqualityComparer<ProjectTemplateConfigValue>
{
bool IEqualityComparer<ProjectTemplateConfigValue>.Equals(ProjectTemplateConfigValue? x, ProjectTemplateConfigValue? y)
{
if (x == null)
{
return y == null;
}
if (y == null)
{
return x == null;
}
if (ReferenceEquals(x, y))
{
return true;
}
return x.Description == y.Description && x.Default == y.Default && x.Secret == y.Secret;
}
int IEqualityComparer<ProjectTemplateConfigValue>.GetHashCode(ProjectTemplateConfigValue obj)
{
return HashCode.Combine(obj.Description, obj.Default, obj.Secret);
}
}
}
}