private void AnalyzeObjectInitSyntax(SyntaxNodeAnalysisContext context) { var initializer = (InitializerExpressionSyntax)context.Node; if (initializer.Parent is AssignmentExpressionSyntax assignment && assignment.Left != null) { var annotatedParent = SyntaxHelper.FindNearestContainer <ObjectCreationExpressionSyntax, MethodDeclarationSyntax>(initializer.Parent, node => IsMarkedWithComment(node, "FullInitRequired:recursive")); if (annotatedParent is null) { return; } var typeInfo = context.SemanticModel.GetTypeInfo(assignment.Left); if (typeInfo.Type != null) { var membersExtractor = new MembersExtractor(context.SemanticModel, initializer); var membersForInitialization = membersExtractor.GetAllMembersThatCanBeInitialized(typeInfo.Type).Select(x => x.Name).ToImmutableHashSet(); if (membersForInitialization.IsEmpty) { return; } TryToReportMissingMembers(context, initializer, membersForInitialization, initializer.GetLocation()); } } }
private IEnumerable <ISymbol> GetMembersForRequiredInit(ITypeSymbol type, ObjectCreationExpressionSyntax objectCreation, SemanticModel semanticModel) { var membersExtractor = new MembersExtractor(semanticModel, objectCreation); if (IsInsideInitBlockWithFullInit(objectCreation) || SymbolHelper.IsMarkedWithAttribute(type, SmartAnnotations.InitRequired) || SymbolHelper.IsMarkedWithAttribute(type, SmartAnnotations.InitOnly)) { return(membersExtractor.GetAllMembersThatCanBeInitialized(type)); } var symbolCache = new SymbolHelperCache(); return(membersExtractor.GetAllMembersThatCanBeInitialized(type).Where(memberSymbol => SymbolHelper.IsMarkedWithAttribute(memberSymbol, SmartAnnotations.InitRequired) || SymbolHelper.IsMarkedWithAttribute(memberSymbol, SmartAnnotations.InitOnly) || NonNullableShouldBeInitialized(memberSymbol, symbolCache))); }