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 7 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
83 changes: 41 additions & 42 deletions dev/VSIX/Extension/Cs/Dev17/VSPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,51 @@
using System.Threading;
using Task = System.Threading.Tasks.Task;

namespace WindowsAppSDK.Cs.Extension
namespace WindowsAppSDK.Cs.Extension;

/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by &lt;Asset Type="Microsoft.VisualStudio.VsPackage" ...&gt; in .vsixmanifest file.
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(VSPackage.PackageGuidString)]
public sealed partial class VSPackage : AsyncPackage
{
/// <summary>
/// This is the class that implements the package exposed by this assembly.
/// VSPackage GUID string.
///
/// NOTE: This MUST match the MSBuild property 'PackageGuidString' defined in the .csproj
/// </summary>
/// <remarks>
/// <para>
/// The minimum requirement for a class to be considered a valid package for Visual Studio
/// is to implement the IVsPackage interface and register itself with the shell.
/// This package uses the helper classes defined inside the Managed Package Framework (MPF)
/// to do it: it derives from the Package class that provides the implementation of the
/// IVsPackage interface and uses the registration attributes defined in the framework to
/// register itself and its components with the shell. These attributes tell the pkgdef creation
/// utility what data to put into .pkgdef file.
/// </para>
/// <para>
/// To get loaded into VS, the package must be referred by &lt;Asset Type="Microsoft.VisualStudio.VsPackage" ...&gt; in .vsixmanifest file.
/// </para>
/// </remarks>
[PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
[Guid(VSPackage.PackageGuidString)]
public sealed class VSPackage : AsyncPackage
{
/// <summary>
/// VSPackage GUID string.
///
/// NOTE: This MUST match the MSBuild property 'PackageGuidString' defined in the .csproj
/// </summary>
public const string PackageGuidString = "B0F1BA01-DE66-4EF9-9C8B-DBB99FB4DA4B";
public const string PackageGuidString = "B0F1BA01-DE66-4EF9-9C8B-DBB99FB4DA4B";

#region Package Members
#region Package Members

/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}

#endregion
/// <summary>
/// Initialization of the package; this method is called right after the package is sited, so this is the place
/// where you can put all the initialization code that rely on services provided by VisualStudio.
/// </summary>
/// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
/// <param name="progress">A provider for progress updates.</param>
/// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress<ServiceProgressData> progress)
{
// When initialized asynchronously, the current thread may be a background thread at this point.
// Do any initialization that requires the UI thread after switching to the UI thread.
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
}

#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>
Loading
Loading