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

Update C# templates to introduce file scoped namespaces #4911

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/VSIX/Extension/Cs/Dev17/VSPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace WindowsAppSDK.Cs.Extension
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(VSPackage.PackageGuidString)]
public sealed class VSPackage : AsyncPackage
public sealed partial class VSPackage : AsyncPackage
{
/// <summary>
/// VSPackage GUID string.
Expand All @@ -55,4 +55,4 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke

#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
mc:Ignorable="d"
Title="$itemname$">

<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Window
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Window
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
mc:Ignorable="d"
Title="$itemname$">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
xmlns:local="using:$rootnamespace$"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
mc:Ignorable="d">

<Grid>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Page
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class $safeitemname$ : Page
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

public sealed partial class $safeitemname$ : Control
{
public sealed class $safeitemname$ : Control
public $safeitemname$()
{
public $safeitemname$()
{
this.DefaultStyleKey = typeof($safeitemname$);
}
DefaultStyleKey = typeof($safeitemname$);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $rootnamespace$
namespace $rootnamespace$;

public sealed partial class $safeitemname$ : UserControl
{
public sealed partial class $safeitemname$ : UserControl
public $safeitemname$()
{
public $safeitemname$()
{
this.InitializeComponent();
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
2 changes: 0 additions & 2 deletions dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ namespace winrt::$rootnamespace$::implementation
{
throw hresult_not_implemented();
}

void $safeitemname$::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
myButton().Content(box_value(L"Clicked"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ namespace winrt::$rootnamespace$::implementation

int32_t MyProperty();
void MyProperty(int32_t value);

void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Grid>

</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

public partial class Class1
{
public class Class1
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window? _window;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
InitializeComponent();
}

private Window? m_window;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
_window = new MainWindow();
_window.Activate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
mc:Ignorable="d"
Title="$projectname$">

haonanttt marked this conversation as resolved.
Show resolved Hide resolved
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Window.SystemBackdrop>
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,15 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
{
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainWindow : Window
public MainWindow()
{
public MainWindow()
{
this.InitializeComponent();
}

private void myButton_Click(object sender, RoutedEventArgs e)
haonanttt marked this conversation as resolved.
Show resolved Hide resolved
{
myButton.Content = "Clicked";
}
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,31 @@
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace $safeprojectname$
namespace $safeprojectname$;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
private Window? _window;

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public partial class App : Application
public App()
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}
InitializeComponent();
}

private Window? m_window;
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
_window = new MainWindow();
_window.Activate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
mc:Ignorable="d"
Title="$projectname$">

haonanttt marked this conversation as resolved.
Show resolved Hide resolved
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
<Window.SystemBackdrop>
haonanttt marked this conversation as resolved.
Show resolved Hide resolved
<MicaBackdrop />
</Window.SystemBackdrop>

<Grid>

</Grid>
</Window>
Loading