diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs index bc3178d6fa8..1ba5c96220e 100644 --- a/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs +++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/CimSessionProxy.cs @@ -2114,10 +2114,10 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) if (context.PropertyName != null) { - pattern = new WildcardPattern(context.PropertyName, WildcardOptions.IgnoreCase); bool match = false; if (cimClass.CimClassProperties != null) { + pattern = new WildcardPattern(context.PropertyName, WildcardOptions.IgnoreCase); foreach (CimPropertyDeclaration decl in cimClass.CimClassProperties) { DebugHelper.WriteLog("--- property name : {0}", 1, decl.Name); @@ -2138,10 +2138,10 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) if (context.MethodName != null) { - pattern = new WildcardPattern(context.MethodName, WildcardOptions.IgnoreCase); bool match = false; if (cimClass.CimClassMethods != null) { + pattern = new WildcardPattern(context.MethodName, WildcardOptions.IgnoreCase); foreach (CimMethodDeclaration decl in cimClass.CimClassMethods) { DebugHelper.WriteLog("--- method name : {0}", 1, decl.Name); @@ -2162,10 +2162,10 @@ protected override bool PreNewActionEvent(CmdletActionEventArgs args) if (context.QualifierName != null) { - pattern = new WildcardPattern(context.QualifierName, WildcardOptions.IgnoreCase); bool match = false; if (cimClass.CimClassQualifiers != null) { + pattern = new WildcardPattern(context.QualifierName, WildcardOptions.IgnoreCase); foreach (CimQualifier qualifier in cimClass.CimClassQualifiers) { DebugHelper.WriteLog("--- qualifier name : {0}", 1, qualifier.Name); diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs index 7b6a7c64d51..378f20147db 100644 --- a/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Diagnostics/GetEventCommand.cs @@ -608,11 +608,10 @@ private void ProcessListLog() foreach (string logPattern in _listLog) { bool bMatchFound = false; + WildcardPattern wildLogPattern = new WildcardPattern(logPattern, WildcardOptions.IgnoreCase); foreach (string logName in eventLogSession.GetLogNames()) { - WildcardPattern wildLogPattern = new WildcardPattern(logPattern, WildcardOptions.IgnoreCase); - if (((!WildcardPattern.ContainsWildcardCharacters(logPattern)) && string.Equals(logPattern, logName, StringComparison.CurrentCultureIgnoreCase)) || @@ -679,11 +678,10 @@ private void ProcessListProvider() foreach (string provPattern in _listProvider) { bool bMatchFound = false; + WildcardPattern wildProvPattern = new WildcardPattern(provPattern, WildcardOptions.IgnoreCase); foreach (string provName in eventLogSession.GetProviderNames()) { - WildcardPattern wildProvPattern = new WildcardPattern(provPattern, WildcardOptions.IgnoreCase); - if (((!WildcardPattern.ContainsWildcardCharacters(provPattern)) && string.Equals(provPattern, provName, StringComparison.CurrentCultureIgnoreCase)) || @@ -2059,10 +2057,10 @@ private void FindLogNamesMatchingWildcards(EventLogSession eventLogSession, IEnu foreach (string logPattern in logPatterns) { bool bMatched = false; + WildcardPattern wildLogPattern = new WildcardPattern(logPattern, WildcardOptions.IgnoreCase); + foreach (string actualLogName in eventLogSession.GetLogNames()) { - WildcardPattern wildLogPattern = new WildcardPattern(logPattern, WildcardOptions.IgnoreCase); - if (((!WildcardPattern.ContainsWildcardCharacters(logPattern)) && (logPattern.Equals(actualLogName, StringComparison.CurrentCultureIgnoreCase))) || @@ -2128,10 +2126,10 @@ private void FindProvidersByLogForWildcardPatterns(EventLogSession eventLogSessi foreach (string provPattern in providerPatterns) { bool bMatched = false; + WildcardPattern wildProvPattern = new WildcardPattern(provPattern, WildcardOptions.IgnoreCase); + foreach (string provName in eventLogSession.GetProviderNames()) { - WildcardPattern wildProvPattern = new WildcardPattern(provPattern, WildcardOptions.IgnoreCase); - if (((!WildcardPattern.ContainsWildcardCharacters(provPattern)) && (provPattern.Equals(provName, StringComparison.CurrentCultureIgnoreCase))) || diff --git a/src/System.Management.Automation/engine/regex.cs b/src/System.Management.Automation/engine/regex.cs index f4e7ee1ecd6..086d459a19f 100644 --- a/src/System.Management.Automation/engine/regex.cs +++ b/src/System.Management.Automation/engine/regex.cs @@ -65,8 +65,9 @@ public sealed class WildcardPattern // wildcard pattern internal string Pattern { get; } - // options that control match behavior - internal WildcardOptions Options { get; } = WildcardOptions.None; + // Options that control match behavior. + // Default is WildcardOptions.None. + internal WildcardOptions Options { get; } /// /// Wildcard pattern converted to regex pattern. @@ -86,15 +87,8 @@ internal string PatternConvertedToRegex /// /// The wildcard pattern to match. /// The constructed WildcardPattern object. - /// if wildCardType == None, the pattern does not have wild cards - public WildcardPattern(string pattern) + public WildcardPattern(string pattern) : this(pattern, WildcardOptions.None) { - if (pattern == null) - { - throw PSTraceSource.NewArgumentNullException("pattern"); - } - - Pattern = pattern; } /// @@ -105,13 +99,11 @@ public WildcardPattern(string pattern) /// The wildcard pattern to match. /// Wildcard options. /// The constructed WildcardPattern object. - /// if wildCardType == None, the pattern does not have wild cards - public WildcardPattern(string pattern, - WildcardOptions options) + public WildcardPattern(string pattern, WildcardOptions options) { if (pattern == null) { - throw PSTraceSource.NewArgumentNullException("pattern"); + throw PSTraceSource.NewArgumentNullException(nameof(pattern)); } Pattern = pattern;