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

Use file-scoped namespaces #9619

Merged
merged 4 commits into from
Dec 12, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ dotnet_naming_style.pascal_case_and_prefix_with_I_style.capitalization
# CSharp code style settings:
[*.cs]

# Use file-scoped namespaces
csharp_style_namespace_declarations = file_scoped:error

# Prefer "var" only when the type is apparent
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
Expand Down
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# convert solution to use file-scoped namespaces
e13927f27b47320d8179af850b1ea31e8b24e12b
51 changes: 25 additions & 26 deletions setup/Common/ProvideCodeBaseBindingRedirection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,35 @@

using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio
namespace Microsoft.VisualStudio;

/// <summary>
/// A <see cref="RegistrationAttribute"/> that provides code-base binding redirects.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class ProvideCodeBaseBindingRedirectionAttribute : RegistrationAttribute
{
/// <summary>
/// A <see cref="RegistrationAttribute"/> that provides code-base binding redirects.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class ProvideCodeBaseBindingRedirectionAttribute : RegistrationAttribute
{
private readonly ProvideBindingRedirectionAttribute _redirectionAttribute;
private readonly ProvideBindingRedirectionAttribute _redirectionAttribute;

public ProvideCodeBaseBindingRedirectionAttribute(string assemblyName)
public ProvideCodeBaseBindingRedirectionAttribute(string assemblyName)
{
// ProvideBindingRedirectionAttribute is sealed, so we can't inherit from it to provide defaults.
// Instead, we'll do more of an aggregation pattern here.
_redirectionAttribute = new ProvideBindingRedirectionAttribute
{
// ProvideBindingRedirectionAttribute is sealed, so we can't inherit from it to provide defaults.
// Instead, we'll do more of an aggregation pattern here.
_redirectionAttribute = new ProvideBindingRedirectionAttribute
{
AssemblyName = assemblyName,
OldVersionLowerBound = "0.0.0.0",
CodeBase = assemblyName + ".dll",
};
}
AssemblyName = assemblyName,
OldVersionLowerBound = "0.0.0.0",
CodeBase = assemblyName + ".dll",
};
}

public override void Register(RegistrationContext context)
{
_redirectionAttribute.Register(context);
}
public override void Register(RegistrationContext context)
{
_redirectionAttribute.Register(context);
}

public override void Unregister(RegistrationContext context)
{
_redirectionAttribute.Unregister(context);
}
public override void Unregister(RegistrationContext context)
{
_redirectionAttribute.Unregister(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

#pragma warning disable CA1200 // Avoid using cref tags with a prefix

namespace Microsoft.VisualStudio
namespace Microsoft.VisualStudio;

/// <summary>
/// Represents timer IDs that are passed to <see cref="T:Microsoft.Internal.Performance.CodeMarker"/>.
/// </summary>
internal static class CodeMarkerTimerId
{
/// <summary>
/// Represents timer IDs that are passed to <see cref="T:Microsoft.Internal.Performance.CodeMarker"/>.
/// Indicates that NuGet package restore has finished.
/// </summary>
internal static class CodeMarkerTimerId
{
/// <summary>
/// Indicates that NuGet package restore has finished.
/// </summary>
public const int PerfPackageRestoreEnd = 7343;
}
public const int PerfPackageRestoreEnd = 7343;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,75 @@
using System.Runtime.InteropServices;
using Path = Microsoft.IO.Path;

namespace Microsoft.VisualStudio.IO
namespace Microsoft.VisualStudio.IO;

[Export(typeof(IFileExplorer))]
internal class WindowsFileExplorer : IFileExplorer
{
[Export(typeof(IFileExplorer))]
internal class WindowsFileExplorer : IFileExplorer
private readonly IFileSystem _fileSystem;

[ImportingConstructor]
public WindowsFileExplorer(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
}

public void OpenContainingFolder(string path)
{
private readonly IFileSystem _fileSystem;
Requires.NotNullOrEmpty(path);

[ImportingConstructor]
public WindowsFileExplorer(IFileSystem fileSystem)
// When 'path' doesn't exist, Explorer just opens the default
// "Quick Access" page, so try to something better than that.
if (_fileSystem.PathExists(path))
{
_fileSystem = fileSystem;
// Tell Explorer to open the parent folder of the item, selecting the item
ShellExecute(
string.Empty,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "explorer.exe"),
parameters: $"/select,\"{path}\"");
}

public void OpenContainingFolder(string path)
else
{
Requires.NotNullOrEmpty(path);

// When 'path' doesn't exist, Explorer just opens the default
// "Quick Access" page, so try to something better than that.
if (_fileSystem.PathExists(path))
{
// Tell Explorer to open the parent folder of the item, selecting the item
ShellExecute(
string.Empty,
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "explorer.exe"),
parameters: $"/select,\"{path}\"");
}
else
string? parentPath = GetParentPath(path);
if (parentPath is not null && _fileSystem.DirectoryExists(parentPath))
{
string? parentPath = GetParentPath(path);
if (parentPath is not null && _fileSystem.DirectoryExists(parentPath))
{
OpenFolder(parentPath);
}
OpenFolder(parentPath);
}
}
}

public void OpenFolder(string path)
{
Requires.NotNullOrEmpty(path);
public void OpenFolder(string path)
{
Requires.NotNullOrEmpty(path);

// Tell Explorer just open the contents of the folder, selecting nothing
ShellExecute("explore", path);
}
// Tell Explorer just open the contents of the folder, selecting nothing
ShellExecute("explore", path);
}

protected static void ShellExecute(string operation, string filePath, string? parameters = null)
{
// Workaround of CLR bug 1134711; System.Diagnostics.Process.Start() does not support GB18030
_ = ShellExecute(IntPtr.Zero, operation, filePath, parameters, lpDirectory: null, 1);
}
protected static void ShellExecute(string operation, string filePath, string? parameters = null)
{
// Workaround of CLR bug 1134711; System.Diagnostics.Process.Start() does not support GB18030
_ = ShellExecute(IntPtr.Zero, operation, filePath, parameters, lpDirectory: null, 1);
}

private static string? GetParentPath(string path)
private static string? GetParentPath(string path)
{
// Remove trailing slashes, so that GetDirectoryName returns
// "Foo" in C:\Foo\Project\" instead of "C:\Foo\Project".
if (Path.EndsInDirectorySeparator(path))
{
// Remove trailing slashes, so that GetDirectoryName returns
// "Foo" in C:\Foo\Project\" instead of "C:\Foo\Project".
if (Path.EndsInDirectorySeparator(path))
{
path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}

return Path.GetDirectoryName(path);
path = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
}

[DllImport("shell32.dll", EntryPoint = "ShellExecuteW")]
internal static extern IntPtr ShellExecute(
IntPtr hwnd,
[MarshalAs(UnmanagedType.LPWStr)] string lpOperation,
[MarshalAs(UnmanagedType.LPWStr)] string lpFile,
[MarshalAs(UnmanagedType.LPWStr)] string? lpParameters,
[MarshalAs(UnmanagedType.LPWStr)] string? lpDirectory,
int nShowCmd);
return Path.GetDirectoryName(path);
}

[DllImport("shell32.dll", EntryPoint = "ShellExecuteW")]
internal static extern IntPtr ShellExecute(
IntPtr hwnd,
[MarshalAs(UnmanagedType.LPWStr)] string lpOperation,
[MarshalAs(UnmanagedType.LPWStr)] string lpFile,
[MarshalAs(UnmanagedType.LPWStr)] string? lpParameters,
[MarshalAs(UnmanagedType.LPWStr)] string? lpDirectory,
int nShowCmd);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Microsoft.VisualStudio.Input
namespace Microsoft.VisualStudio.Input;

/// <summary>
/// Provides common well-known command groups.
/// </summary>
internal static class CommandGroup
{
/// <summary>
/// Provides common well-known command groups.
/// </summary>
internal static class CommandGroup
{
public const string UIHierarchyWindow = VSConstants.CMDSETID.UIHierarchyWindowCommandSet_string;
public const string VisualStudioStandard97 = VSConstants.CMDSETID.StandardCommandSet97_string;
public const string VisualStudioStandard2k = VSConstants.CMDSETID.StandardCommandSet2K_string;
public const string FSharpProject = "{75AC5611-A912-4195-8A65-457AE17416FB}";
public const string ManagedProjectSystemOrder = "{6C4806E9-034E-4B64-99DE-29A6F837B993}";
public const string ManagedProjectSystem = "{568ABDF7-D522-474D-9EED-34B5E5095BA5}";
public const string WPF = "{A8878AC2-6163-4C15-9767-1871DD750C6A}";
}
public const string UIHierarchyWindow = VSConstants.CMDSETID.UIHierarchyWindowCommandSet_string;
public const string VisualStudioStandard97 = VSConstants.CMDSETID.StandardCommandSet97_string;
public const string VisualStudioStandard2k = VSConstants.CMDSETID.StandardCommandSet2K_string;
public const string FSharpProject = "{75AC5611-A912-4195-8A65-457AE17416FB}";
public const string ManagedProjectSystemOrder = "{6C4806E9-034E-4B64-99DE-29A6F837B993}";
public const string ManagedProjectSystem = "{568ABDF7-D522-474D-9EED-34B5E5095BA5}";
public const string WPF = "{A8878AC2-6163-4C15-9767-1871DD750C6A}";
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Microsoft.VisualStudio.Input
namespace Microsoft.VisualStudio.Input;

// from VS: src\vsproject\cool\coolpkg\resource.h
internal enum LegacyCSharpStringResourceIds : uint
{
// from VS: src\vsproject\cool\coolpkg\resource.h
internal enum LegacyCSharpStringResourceIds : uint
{
IDS_TEMPLATE_NEWWFCWIN32FORM = 2237,
IDS_TEMPLATE_DIRLOCALITEMS = 2339,
IDS_TEMPLATE_NEWCSharpCLASS = 2245,
IDS_TEMPLATE_NEWWFCCOMPONENT = 2246,
IDS_TEMPLATE_NEWUSERCONTROL = 2295,
IDS_PROJECTITEMTYPE_STR = 2346,
}
IDS_TEMPLATE_NEWWFCWIN32FORM = 2237,
IDS_TEMPLATE_DIRLOCALITEMS = 2339,
IDS_TEMPLATE_NEWCSharpCLASS = 2245,
IDS_TEMPLATE_NEWWFCCOMPONENT = 2246,
IDS_TEMPLATE_NEWUSERCONTROL = 2295,
IDS_PROJECTITEMTYPE_STR = 2346,
}

// from VS: src\vsproject\vb\vbprj\vbprjstr.h
internal enum LegacyVBStringResourceIds : uint
{
IDS_VSDIR_ITEM_CLASS = 3020,
IDS_VSDIR_ITEM_COMPONENT = 3024,
IDS_VSDIR_ITEM_MODULE = 3028,
IDS_VSDIR_ITEM_USERCTRL = 3048,
IDS_VSDIR_ITEM_WINFORM = 3050,
IDS_VSDIR_CLIENTPROJECTITEMS = 3081,
IDS_VSDIR_VBPROJECTFILES = 3082,
}
// from VS: src\vsproject\vb\vbprj\vbprjstr.h
internal enum LegacyVBStringResourceIds : uint
{
IDS_VSDIR_ITEM_CLASS = 3020,
IDS_VSDIR_ITEM_COMPONENT = 3024,
IDS_VSDIR_ITEM_MODULE = 3028,
IDS_VSDIR_ITEM_USERCTRL = 3048,
IDS_VSDIR_ITEM_WINFORM = 3050,
IDS_VSDIR_CLIENTPROJECTITEMS = 3081,
IDS_VSDIR_VBPROJECTFILES = 3082,
}

// from VS: src\vsproject\fidalgo\WPF\Flavor\WPFFlavor\WPFProject.cs
internal enum WPFTemplateNames : uint
{
WPFPage = 4658,
WPFResourceDictionary = 4662,
WPFUserControl = 4664,
WPFWindow = 4666,
}
// from VS: src\vsproject\fidalgo\WPF\Flavor\WPFFlavor\WPFProject.cs
internal enum WPFTemplateNames : uint
{
WPFPage = 4658,
WPFResourceDictionary = 4662,
WPFUserControl = 4664,
WPFWindow = 4666,
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Microsoft.VisualStudio.Input
namespace Microsoft.VisualStudio.Input;

/// <summary>
/// Provides common well-known F# command IDs.
/// </summary>
internal static class FSharpProjectCommandId
{
/// <summary>
/// Provides common well-known F# command IDs.
/// </summary>
internal static class FSharpProjectCommandId
{
public const int MoveUp = 0x3002;
public const int MoveDown = 0x3007;
}
public const int MoveUp = 0x3002;
public const int MoveDown = 0x3007;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

namespace Microsoft.VisualStudio.Input
namespace Microsoft.VisualStudio.Input;

/// <summary>
/// Provides common well-known project-system command IDs.
/// </summary>
internal static class ManagedProjectSystemCommandId
{
/// <summary>
/// Provides common well-known project-system command IDs.
/// </summary>
internal static class ManagedProjectSystemCommandId
{
public const long GenerateNuGetPackageProjectContextMenu = 0x2000;
public const long GenerateNuGetPackageTopLevelBuild = 0x2001;
public const long NavigateToProject = 0x2002;
public const int DebugTargetMenuDebugFrameworkMenu = 0x3000;
public const int DebugFrameworks = 0x3050;
}
public const long GenerateNuGetPackageProjectContextMenu = 0x2000;
public const long GenerateNuGetPackageTopLevelBuild = 0x2001;
public const long NavigateToProject = 0x2002;
public const int DebugTargetMenuDebugFrameworkMenu = 0x3000;
public const int DebugFrameworks = 0x3050;
}
Loading
Loading