Merge pull request #2998 from bkoelman/equals-fix
Fixed broken Equals (2)
This commit is contained in:
commit
f515e80029
2 changed files with 36 additions and 21 deletions
|
@ -1,9 +1,11 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel
|
||||
{
|
||||
public class AnalyzerOptions
|
||||
public class AnalyzerOptions : IEquatable<AnalyzerOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// The identifier indicating the project language as defined by NuGet.
|
||||
|
@ -11,32 +13,45 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
/// <remarks>
|
||||
/// See https://docs.nuget.org/create/analyzers-conventions for valid values
|
||||
/// </remarks>
|
||||
public string LanguageId { get; set; }
|
||||
public string LanguageId { get; }
|
||||
|
||||
public AnalyzerOptions(string languageId = null)
|
||||
{
|
||||
LanguageId = languageId;
|
||||
}
|
||||
|
||||
public bool Equals(AnalyzerOptions other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && other.LanguageId == LanguageId;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as AnalyzerOptions);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return LanguageId?.GetHashCode() ?? 0;
|
||||
}
|
||||
|
||||
public static bool operator ==(AnalyzerOptions left, AnalyzerOptions right)
|
||||
{
|
||||
return left.LanguageId == right.LanguageId;
|
||||
if (ReferenceEquals(left, right))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (ReferenceEquals(left, null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return left.Equals(right);
|
||||
}
|
||||
|
||||
public static bool operator !=(AnalyzerOptions left, AnalyzerOptions right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var options = obj as AnalyzerOptions;
|
||||
return obj != null && (this == options);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return LanguageId.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -561,7 +561,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
analyzerOption.Value.ToString(),
|
||||
project.ProjectFilePath);
|
||||
}
|
||||
analyzerOptions.LanguageId = analyzerOption.Value.ToString();
|
||||
analyzerOptions = new AnalyzerOptions(analyzerOption.Value.ToString());
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue