From 083bc52b341676f8845d0a4d3c59991a46eaf19f Mon Sep 17 00:00:00 2001 From: Mike McLaughlin Date: Wed, 11 Dec 2019 22:09:48 -0800 Subject: [PATCH] Add setclrpath command to dotnet-dump on linux. Mentioned in https://github.com/dotnet/diagnostics/issues/624 --- .../Command/Attributes.cs | 24 ---------------- .../Command/CommandProcessor.cs | 28 +++++++++++++++++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.Diagnostics.Repl/Command/Attributes.cs b/src/Microsoft.Diagnostics.Repl/Command/Attributes.cs index 5e936c8a8d..5690cb2e6c 100644 --- a/src/Microsoft.Diagnostics.Repl/Command/Attributes.cs +++ b/src/Microsoft.Diagnostics.Repl/Command/Attributes.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Runtime.InteropServices; namespace Microsoft.Diagnostics.Repl { @@ -44,29 +43,6 @@ public class CommandBaseAttribute : BaseAttribute /// Optional OS platform for the command /// public CommandPlatform Platform = CommandPlatform.All; - - /// - /// Returns true if the command should be added. - /// - public bool IsValidPlatform() - { - if (Platform != CommandPlatform.All) - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return (Platform & CommandPlatform.Windows) != 0; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return (Platform & CommandPlatform.Linux) != 0; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - return (Platform & CommandPlatform.OSX) != 0; - } - } - return true; - } } /// diff --git a/src/Microsoft.Diagnostics.Repl/Command/CommandProcessor.cs b/src/Microsoft.Diagnostics.Repl/Command/CommandProcessor.cs index a637d9da6c..992d4e0e1e 100644 --- a/src/Microsoft.Diagnostics.Repl/Command/CommandProcessor.cs +++ b/src/Microsoft.Diagnostics.Repl/Command/CommandProcessor.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace Microsoft.Diagnostics.Repl @@ -116,7 +117,7 @@ private void BuildCommands(CommandLineBuilder rootBuilder, Type type) { if (baseAttribute is CommandAttribute commandAttribute) { - if (commandAttribute.IsValidPlatform()) + if (IsValidPlatform(commandAttribute)) { command = new Command(commandAttribute.Name, commandAttribute.Help); var properties = new List<(PropertyInfo, Option)>(); @@ -172,7 +173,7 @@ private void BuildCommands(CommandLineBuilder rootBuilder, Type type) if (baseAttribute is CommandAliasAttribute commandAliasAttribute) { - if (commandAliasAttribute.IsValidPlatform()) + if (IsValidPlatform(commandAliasAttribute)) { if (command == null) { @@ -196,6 +197,29 @@ private T GetService() return service; } + /// + /// Returns true if the command should be added. + /// + private static bool IsValidPlatform(CommandBaseAttribute attribute) + { + if (attribute.Platform != CommandPlatform.All) + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return (attribute.Platform & CommandPlatform.Windows) != 0; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return (attribute.Platform & CommandPlatform.Linux) != 0; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return (attribute.Platform & CommandPlatform.OSX) != 0; + } + } + return true; + } + private static string BuildAlias(string parameterName) { if (string.IsNullOrWhiteSpace(parameterName)) {