Skip to content

Commit

Permalink
Fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
Vannevelj committed Apr 16, 2020
1 parent e3a438f commit 285bb69
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void Method()
class MyCollectionItem {}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand Down Expand Up @@ -70,7 +70,7 @@ void Method()
struct MyCollectionItem {}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand All @@ -97,7 +97,7 @@ public override bool Equals(object obj)
}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand All @@ -124,7 +124,7 @@ public override bool Equals(object obj)
}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand All @@ -151,7 +151,7 @@ public override int GetHashCode()
}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand All @@ -178,7 +178,7 @@ public override int GetHashCode()
}
}";

VerifyDiagnostic(original, ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand Down Expand Up @@ -264,8 +264,8 @@ class MyCollectionItem {}
}";

VerifyDiagnostic(original,
ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString(),
ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
"Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.",
"Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand All @@ -286,8 +286,7 @@ void Method()
class MyCollectionItem {}
}";

VerifyDiagnostic(original,
ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer.Rule.MessageFormat.ToString());
VerifyDiagnostic(original, "Implement Equals() and GetHashCode() methods of type MyCollectionItem for use in a collection.");
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public class ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzer : Diagnost

private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
{
var objectTypeInfo = context.SemanticModel.GetTypeInfo(context.Node).Type as INamedTypeSymbol;

if (objectTypeInfo == null)
if (!( context.SemanticModel.GetTypeInfo(context.Node).Type is INamedTypeSymbol objectTypeInfo ))
{
return;
}
Expand All @@ -40,8 +38,8 @@ private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)
return;
}

var objectType = ( (ObjectCreationExpressionSyntax)context.Node ).Type as GenericNameSyntax;
if (objectType == null)
var node = ( (ObjectCreationExpressionSyntax)context.Node );
if (!( node.Type is GenericNameSyntax objectType ))
{
return;
}
Expand Down Expand Up @@ -78,7 +76,7 @@ private void AnalyzeSymbol(SyntaxNodeAnalysisContext context)

if (!implementsEquals || !implementsGetHashCode)
{
context.ReportDiagnostic(Diagnostic.Create(Rule, genericType.GetLocation()));
context.ReportDiagnostic(Diagnostic.Create(Rule, genericType.GetLocation(), genericTypeInfo.Name));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions sharpsource/sharpsource/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions sharpsource/sharpsource/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@
<value>The operands of a divisive expression are both integers and result in an implicit rounding.</value>
</data>
<data name="ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzerMessage" xml:space="preserve">
<value>Implement elementary methods of type used in collection.</value>
<value>Implement Equals() and GetHashCode() methods of type {0} for use in a collection.</value>
<comment>{0} - Type name</comment>
</data>
<data name="ElementaryMethodsOfTypeInCollectionNotOverriddenAnalyzerTitle" xml:space="preserve">
<value>Implement elementary methods for a type used in a collection.</value>
<value>Implement Equals() and GetHashcode() methods for a type used in a collection.</value>
</data>
<data name="EnumCanHaveFlagsAttributeAnalyzerMessage" xml:space="preserve">
<value>Enum can have [Flags] attribute.</value>
Expand Down

0 comments on commit 285bb69

Please # to comment.