public void List_chain_of_constructors_3() { var codeAsText = File.ReadAllText(@"SyntaxAnalyserExamples/ClassFamily.cs"); var syntaxTree = SyntaxOperations.Parse(codeAsText); var classExtUserDeclarationSyntax = SyntaxOperations.FindClass <ExtendedUser>(syntaxTree).A; var classNormalUserDeclarationSyntax = SyntaxOperations.FindClass <NormalUser>(syntaxTree).A; var classBaseUserDeclarationSyntax = SyntaxOperations.FindClass <BaseUser>(syntaxTree).A; var semanticModel = SemanticOperations.GetSemanticModel(syntaxTree); var threeArgsCtor = SyntaxOperations .FindConstructorsOf(classExtUserDeclarationSyntax, semanticModel, argsCount: 3) .Single(); var(firstLink, isCompleted) = ChainOfConstructor.StartingFrom(threeArgsCtor, classExtUserDeclarationSyntax, semanticModel); var secondLink = firstLink.NextLink.Value; var thirdLink = secondLink.NextLink.Value; var lastlink = thirdLink.NextLink.Value; Assert.IsTrue(isCompleted); _Assert_IsIntermadiateLink(firstLink, classExtUserDeclarationSyntax, threeArgsCtor); _Assert_IsIntermadiateLink(secondLink, classNormalUserDeclarationSyntax, SyntaxOperations.FindConstructorsOf(classNormalUserDeclarationSyntax, semanticModel, 3).Single()); _Assert_IsIntermadiateLink(thirdLink, classNormalUserDeclarationSyntax, SyntaxOperations.FindConstructorsOf(classNormalUserDeclarationSyntax, semanticModel, 2).Single()); _Assert_IsLastLink(lastlink, classBaseUserDeclarationSyntax, SyntaxOperations.FindConstructorsOf(classBaseUserDeclarationSyntax, semanticModel, 0).Single()); }
public void List_chain_of_constructors_2() { var codeAsText = File.ReadAllText(@"SyntaxAnalyserExamples/ClassFamily.cs"); var syntaxTree = SyntaxOperations.Parse(codeAsText); var classDeclarationSyntax = SyntaxOperations.FindClass <BaseUser>(syntaxTree).A; var semanticModel = SemanticOperations.GetSemanticModel(syntaxTree); var zeroArgsCtor = SyntaxOperations .FindConstructorsOf(classDeclarationSyntax, semanticModel, argsCount: 0) .Single(); var oneArgCtor = SyntaxOperations .FindConstructorsOf(classDeclarationSyntax, semanticModel, argsCount: 1) .Single(); var(firstLink, isCompleted) = ChainOfConstructor.StartingFrom(oneArgCtor, classDeclarationSyntax, semanticModel); Assert.IsTrue(isCompleted); _Assert_IsIntermadiateLink(firstLink, classDeclarationSyntax, oneArgCtor); var secondLink = firstLink.NextLink.Value; _Assert_IsLastLink(secondLink, classDeclarationSyntax, zeroArgsCtor); }
public void Partial_chain_of_constructors_can_be_obtained_from_partial_code_2() { var codeAsText2 = File.ReadAllText(@"SyntaxAnalyserExamples/PartialClass.part2.cs"); var syntaxTree2 = SyntaxOperations.Parse(codeAsText2); var classDeclarationSyntax2 = SyntaxOperations.FindClass <PartialClass>(syntaxTree2).A; var semanticModel = SemanticOperations.GetSemanticModel(syntaxTree2, new[] { syntaxTree2 }); var twoArgsCtor = SyntaxOperations .FindConstructorsOf(classDeclarationSyntax2, semanticModel, argsCount: 2) .Single(); var(firstLink, isCompleted) = ChainOfConstructor.StartingFrom(twoArgsCtor, classDeclarationSyntax2, semanticModel); Assert.IsFalse(isCompleted); _Assert_IsIntermadiateLink(firstLink, classDeclarationSyntax2, twoArgsCtor); }