Skip to content

Instantly share code, notes, and snippets.

@Vannevelj
Last active August 29, 2015 14:00
Show Gist options
  • Save Vannevelj/11351301 to your computer and use it in GitHub Desktop.
Save Vannevelj/11351301 to your computer and use it in GitHub Desktop.
foreach (var argument in genericTypeParameters.Arguments)
{
var typeInfo = semanticModel.GetTypeInfo(argument);
var dir = @"C:\Users\Jeroen\Documents\Visual Studio 2013\Projects\RoslynTester";
var solution = MSBuildWorkspace.Create().OpenSolutionAsync(dir).Result;
var syntaxRoots =
from project in solution.Projects
from document in project.Documents
select document.GetSyntaxRootAsync().Result;
var diagnostic = Diagnostic.Create(Rule, declaration.GetLocation(), typeInfo.Type.Name, declaration.Variables[0].Identifier);
foreach (var root in syntaxRoots)
{
new FindOverrides(addDiagnostic, diagnostic).Visit(root);
}
}
public class FindOverrides : CSharpSyntaxWalker
{
private Action<Diagnostic> _addDiagnostic;
private Diagnostic _diagnostic;
public FindOverrides(Action<Diagnostic> addDiagnostic, Diagnostic diagnostic)
{
_addDiagnostic = addDiagnostic;
_diagnostic = diagnostic;
}
public override void VisitMethodDeclaration(MethodDeclarationSyntax node)
{
base.VisitMethodDeclaration(node);
if (node.Identifier.Text == "Equals"
&& node.Modifiers.Any(m => m.Text == "override"))
{
_addDiagnostic(_diagnostic);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment