CodeAction GetActionForLevel(RefactoringContext context, string accessName, Modifiers access, EntityDeclaration node, AstNode selectedNode) { return(new CodeAction(context.TranslateString("To " + accessName), script => { Modifiers newModifiers = node.Modifiers; newModifiers &= ~Modifiers.VisibilityMask; if (!(node is Accessor) || access != (node.GetParent <EntityDeclaration>().Modifiers & Modifiers.VisibilityMask)) { //Do not add access modifier for accessors if the new access level is the same as the parent //That is, in public int X { $private get; } if access == public, then the result should not have the modifier newModifiers |= access; } script.ChangeModifier(node, newModifiers); }, selectedNode)); }
static Modifiers GetActualAccess(AstNode parentTypeDeclaration, EntityDeclaration node) { Modifiers nodeAccess = node.Modifiers & Modifiers.VisibilityMask; if (nodeAccess == Modifiers.None && node is Accessor) { EntityDeclaration parent = node.GetParent <EntityDeclaration>(); nodeAccess = parent.Modifiers & Modifiers.VisibilityMask; } if (nodeAccess == Modifiers.None) { if (parentTypeDeclaration == null) { return(Modifiers.Internal); } return(Modifiers.Private); } return(nodeAccess & Modifiers.VisibilityMask); }