コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }