Example #1
0
        public void ReturnsValidFieldData_When_IsSingleField()
        {
            FieldDeclarationSyntax field         = GetNode <FieldDeclarationSyntax>("class Test { int Age = 0; }");
            SemanticModel          semanticModel = Compilation.CurrentCompilation.GetSemanticModel(field.SyntaxTree);
            IFieldSymbol           symbol        = (semanticModel.GetDeclaredSymbol(field.Declaration.Variables[0]) as IFieldSymbol) !;

            Data.FieldData?data = field.GetMemberData(Compilation) as Data.FieldData;

            Assert.True(ValidateMember(data, field, symbol) && data !.GetUnderlayingFields().Count() == 1);
        }
Example #2
0
        public void ReturnsValidFieldData_When_HasMultipleFieldsInSingleDeclaration()
        {
            FieldDeclarationSyntax field         = GetNode <FieldDeclarationSyntax>("class Test { int Age = 0, Index = 2 }");
            SemanticModel          semanticModel = Compilation.CurrentCompilation.GetSemanticModel(field.SyntaxTree);
            IFieldSymbol           symbol1       = (semanticModel.GetDeclaredSymbol(field.Declaration.Variables[0]) as IFieldSymbol) !;
            IFieldSymbol           symbol2       = (semanticModel.GetDeclaredSymbol(field.Declaration.Variables[1]) as IFieldSymbol) !;

            Data.FieldData?data = field.GetMemberData(Compilation) as Data.FieldData;
            Data.FieldData[]? declaredFields = data?.GetUnderlayingFields().ToArray();

            Assert.True(ValidateMember(data, field, symbol1) && declaredFields !.Length == 2 && ValidateMember(declaredFields[1], field, symbol2));
        }