Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to file-scoped namespace #1689

Closed
AndrewKeepCoding opened this issue Dec 11, 2024 · 6 comments · Fixed by #1700
Closed

Switch to file-scoped namespace #1689

AndrewKeepCoding opened this issue Dec 11, 2024 · 6 comments · Fixed by #1700
Labels
help wanted Extra attention is needed

Comments

@AndrewKeepCoding
Copy link
Contributor

AndrewKeepCoding commented Dec 11, 2024

Issue type

enhancement

Which version of the app?

WinUI 3 Gallery

Description

File-scoped namespace will improve readability.
IMHO, it's something that will be done in the future, so why not now? The sooner, the better.
I'd be happy to do this.

Screenshots

No response

Windows version

No response

Additional context

No response

@Jay-o-Way
Copy link
Contributor

Got an example? :)

@AndrewKeepCoding
Copy link
Contributor Author

For example, App.xaml.cs:

Block-scoped namespace

namespace WinUIGallery
{
    /// <summary>
    /// Provides application-specific behavior to supplement the default Application class.
    /// </summary>
    sealed partial class App : Application
    {
        private static Window startupWindow;

File-scoped namespace

namespace WinUIGallery;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
    private static Window startupWindow;

@Jay-o-Way
Copy link
Contributor

If you let Visual Studio create such a new file, what does it initially look like? Why would VS prefer one over the other?

@AndrewKeepCoding
Copy link
Contributor Author

Yeah. VS's item templates haven't been updated (yet?).
I'm bringing this up because, in the CommunityToolkit/Labs-Windows repo, I saw they are switching to file-scoped namespaces (CommunityToolkit/Labs-Windows#148), and I thought it might be a good idea to apply the same change here too. They also updated the editor.config to issue warnings for block-scoped namespaces.

@karkarl karkarl added help wanted Extra attention is needed and removed needs-triage labels Dec 12, 2024
@karkarl karkarl moved this to 📋 Backlog in WinUI Gallery Backlog Dec 12, 2024
@karkarl
Copy link
Collaborator

karkarl commented Dec 12, 2024

Thanks for filing this issue. Would you want to take a stab at it?

@AndrewKeepCoding
Copy link
Contributor Author

Thanks for filing this issue. Would you want to take a stab at it?

@karkarl Of course!🙂

niels9001 pushed a commit that referenced this issue Jan 27, 2025
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
This PR will switch C# files from block-scoped namespaces to file-scoped
namespaces.
Closes #1689.

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
Improves readability.

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
- Confirmed that all unit tests passes.
- Run the app and navigated through all pages.

## Screenshots (if appropriate):

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

3 participants