public RemoveReadonlyFromSerializedFieldQuickFix(RedundantSerializeFieldAttributeWarning highlighting) { myAttribute = highlighting.Attribute; var attributeSectionList = AttributeSectionListNavigator.GetByAttribute(myAttribute); myMultipleFieldDeclaration = MultipleFieldDeclarationNavigator.GetByAttributes(attributeSectionList); myFieldDeclarations = FieldDeclarationNavigator.GetByAttribute(myAttribute); }
public static CompactList <IField> GetFieldsByAttribute(this IAttribute attribute) { var list = new CompactList <IField>(); foreach (var fieldDeclaration in FieldDeclarationNavigator.GetByAttribute(attribute)) { if (fieldDeclaration.DeclaredElement != null) { list.Add(fieldDeclaration.DeclaredElement); } } foreach (var constantDeclaration in ConstantDeclarationNavigator.GetByAttribute(attribute)) { if (constantDeclaration.DeclaredElement != null) { list.Add(constantDeclaration.DeclaredElement); } } return(list); }
protected override void Analyze(IAttribute attribute, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { if (!(attribute.TypeReference?.Resolve().DeclaredElement is ITypeElement attributeTypeElement)) { return; } if (!Equals(attributeTypeElement.GetClrName(), KnownTypes.SerializeField)) { return; } var fieldDeclarations = FieldDeclarationNavigator.GetByAttribute(attribute); foreach (var fieldDeclaration in fieldDeclarations) { if (fieldDeclaration.DeclaredElement.HasAttributeInstance(PredefinedType.NONSERIALIZED_ATTRIBUTE_CLASS, false)) { consumer.AddHighlighting(new RedundantSerializeFieldAttributeWarning(attribute)); return; } } }