public static void Equivalent() { var syntaxTree = CSharpSyntaxTree.ParseText( @" namespace N { using System; public class C { public event EventHandler E1; public event EventHandler E2; } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); var semanticModel = compilation.GetSemanticModel(syntaxTree); var node1 = syntaxTree.FindEventFieldDeclaration("E1"); var symbol1 = semanticModel.GetDeclaredSymbol(node1.Declaration.Variables[0], CancellationToken.None); var node2 = syntaxTree.FindEventFieldDeclaration("E2"); var symbol2 = semanticModel.GetDeclaredSymbol(node2.Declaration.Variables[0], CancellationToken.None); Assert.AreEqual(true, SymbolComparer.Equivalent(symbol1, symbol1)); Assert.AreEqual(false, SymbolComparer.Equivalent(symbol1, symbol2)); Assert.AreEqual(true, EventSymbolComparer.Equivalent((IEventSymbol)symbol1, (IEventSymbol)symbol1)); Assert.AreEqual(false, EventSymbolComparer.Equivalent((IEventSymbol)symbol1, (IEventSymbol)symbol2)); }
public static void Equivalent() { var syntaxTree = CSharpSyntaxTree.ParseText( @" namespace N { public class C { public int M1() => 1; public int M2() => 2; } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); var semanticModel = compilation.GetSemanticModel(syntaxTree); var node1 = syntaxTree.FindMethodDeclaration("M1"); var symbol1 = semanticModel.GetDeclaredSymbol(node1, CancellationToken.None); var node2 = syntaxTree.FindMethodDeclaration("M2"); var symbol2 = semanticModel.GetDeclaredSymbol(node2, CancellationToken.None); Assert.AreEqual(true, SymbolComparer.Equivalent((ISymbol)symbol1, (ISymbol)symbol1)); Assert.AreEqual(false, SymbolComparer.Equivalent((ISymbol)symbol1, (ISymbol)symbol2)); Assert.AreEqual(true, MethodSymbolComparer.Equivalent(symbol1, symbol1)); Assert.AreEqual(false, MethodSymbolComparer.Equivalent(symbol1, symbol2)); }
public static void Equivalent() { var syntaxTree = CSharpSyntaxTree.ParseText( @" namespace N { public class C { private int f1; private int f2; } }"); var compilation = CSharpCompilation.Create("test", new[] { syntaxTree }); var semanticModel = compilation.GetSemanticModel(syntaxTree); var node1 = syntaxTree.FindFieldDeclaration("f1"); var symbol1 = semanticModel.GetDeclaredSymbol(node1.Declaration.Variables[0], CancellationToken.None); var node2 = syntaxTree.FindFieldDeclaration("f2"); var symbol2 = semanticModel.GetDeclaredSymbol(node2.Declaration.Variables[0], CancellationToken.None); Assert.AreEqual(true, SymbolComparer.Equivalent(symbol1, symbol1)); Assert.AreEqual(false, SymbolComparer.Equivalent(symbol1, symbol2)); Assert.AreEqual(true, FieldSymbolComparer.Equivalent((IFieldSymbol)symbol1, (IFieldSymbol)symbol1)); Assert.AreEqual(false, FieldSymbolComparer.Equivalent((IFieldSymbol)symbol1, (IFieldSymbol)symbol2)); }