public static IAttribute AddAttributeToEntireDeclaration( [NotNull] IMultipleFieldDeclaration multipleFieldDeclaration, IClrTypeName attributeTypeName, [NotNull] AttributeValue[] attributeValues, IPsiModule module, CSharpElementFactory elementFactory) { // TODO: Do we need to do this check here? var existingAttribute = GetAttribute(multipleFieldDeclaration.Attributes, attributeTypeName); if (existingAttribute != null) { return(null); } var attribute = CreateAttribute(attributeTypeName, attributeValues, module, elementFactory); if (attribute != null) { // It doesn't matter which declaration we use, it will be applied to the multiple field declaration var firstFieldDeclaration = (IFieldDeclaration)multipleFieldDeclaration.Declarators[0]; return(CSharpSharedImplUtil.AddAttributeAfter(firstFieldDeclaration, attribute, null)); } return(null); }
protected override void DoRegisterCallbacks( ProjectModelViewHost host, DteProtocolModel model ) { MapWithAstManager( model.CodeElement_get_Children, node => node.GetEnvDTEModelChildren().Select(CreateCodeElementModel).ToList(), element => throw new NotImplementedException(), type => throw new InvalidOperationException() ); MapWithAstManager( model.CodeElement_get_Access, GetAccessRights, GetAccessRights, type => throw new NotImplementedException()); MapWithAstManager( model.CodeElement_get_Name, ElementNameProvider.FindName, element => element.ShortName, type => type.GetPresentableName(CSharpLanguage.Instance.NotNull()) ); MapWithAstManager( model.CodeElement_get_FullName, node => { if (!(node is ICSharpDeclaration declaration)) { return(null); } return(CSharpSharedImplUtil.GetQualifiedName(declaration)); },
public static void RemoveAttributeFromAllDeclarations([CanBeNull] IFieldDeclaration fieldDeclaration, IClrTypeName attributeTypeName) { var attribute = GetAttribute(fieldDeclaration, attributeTypeName); if (attribute != null) { CSharpSharedImplUtil.RemoveAttribute(fieldDeclaration, attribute); } }
protected override Action <ITextControl> ExecutePsiTransaction( ISolution solution, IProgressIndicator progress) { if (mySelectedFieldDeclaration != null) { // This will split any multiple field declarations mySelectedFieldDeclaration.RemoveAttribute(myExistingAttribute); } else { var fieldDeclaration = (IFieldDeclaration)myMultipleFieldDeclaration.Declarators[0]; CSharpSharedImplUtil.RemoveAttribute(fieldDeclaration, myExistingAttribute); } return(null); }
protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress) { var fieldDeclaration = (IFieldDeclaration)myMultipleFieldDeclaration.Declarators[0]; if (myExistingAttribute != null) { CSharpSharedImplUtil.RemoveAttribute(fieldDeclaration, myExistingAttribute); } else { AttributeUtil.AddAttributeToAllDeclarations(fieldDeclaration, KnownTypes.HideInInspector, myModule, myElementFactory); } return(null); }
public static void AddAttributeToAllDeclarations([CanBeNull] IFieldDeclaration fieldDeclaration, IClrTypeName attributeTypeName, IPsiModule psiModule, CSharpElementFactory elementFactory) { if (fieldDeclaration == null) { return; } var existingAttribute = GetAttribute(fieldDeclaration, attributeTypeName); if (existingAttribute != null) { return; } var attribute = CreateAttribute(attributeTypeName, psiModule, elementFactory); if (attribute != null) { CSharpSharedImplUtil.AddAttributeAfter(fieldDeclaration, attribute, null); } }