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

Prefer string alias over String type #3408

Merged
merged 1 commit into from
Feb 23, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private IEnumerable<string> GetTestExtensionsInternal(string extensionType)
object extensionManager;
object settingsManager;

settingsManager = SettingsManagerType.GetMethod("CreateForApplication", new Type[] { typeof(String) }).Invoke(null, new object[] { installContext.GetVisualStudioPath(vsInstallPath) });
settingsManager = SettingsManagerType.GetMethod("CreateForApplication", new Type[] { typeof(string) }).Invoke(null, new object[] { installContext.GetVisualStudioPath(vsInstallPath) });
if (settingsManager != null)
{
try
Expand All @@ -100,7 +100,7 @@ private IEnumerable<string> GetTestExtensionsInternal(string extensionType)

if (extensionManager != null)
{
installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", new Type[] { typeof(String) }).Invoke(
installedExtensions = ExtensionManagerServiceType.GetMethod("GetEnabledExtensionContentLocations", new Type[] { typeof(string) }).Invoke(
extensionManager, new object[] { extensionType }) as IEnumerable<string>;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public string ParseError
/// <summary>
/// Validate if underlying filter expression is valid for given set of supported properties.
/// </summary>
public string[] ValidForProperties(IEnumerable<String> supportedProperties, Func<string, TestProperty> propertyProvider)
public string[] ValidForProperties(IEnumerable<string> supportedProperties, Func<string, TestProperty> propertyProvider)
{
return UseFastFilter ? FastFilter.ValidForProperties(supportedProperties) : _filterExpression?.ValidForProperties(supportedProperties, propertyProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public string TestCaseFilterValue
/// <summary>
/// Validate if underlying filter expression is valid for given set of supported properties.
/// </summary>
public string[] ValidForProperties(IEnumerable<String> supportedProperties, Func<string, TestProperty> propertyProvider)
public string[] ValidForProperties(IEnumerable<string> supportedProperties, Func<string, TestProperty> propertyProvider)
{
string[] invalidProperties = null;
if (null != _filterWrapper && _validForMatch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public TestCategoryItem(string category)
// Treat null as empty.
if (category == null)
{
category = String.Empty;
category = string.Empty;
}


Expand All @@ -52,10 +52,10 @@ public string TestCategory
private string StripIllegalChars(string category)
{
string ret = category.Trim();
ret = ret.Replace("&", String.Empty);
ret = ret.Replace("|", String.Empty);
ret = ret.Replace("!", String.Empty);
ret = ret.Replace(",", String.Empty);
ret = ret.Replace("&", string.Empty);
ret = ret.Replace("|", string.Empty);
ret = ret.Replace("!", string.Empty);
ret = ret.Replace(",", string.Empty);
return ret;
}

Expand All @@ -71,7 +71,7 @@ public override bool Equals(object other)
return false;
}
Debug.Assert(_category != null, "category is null");
return String.Equals(_category, otherItem._category, StringComparison.OrdinalIgnoreCase);
return string.Equals(_category, otherItem._category, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
Expand Down Expand Up @@ -154,7 +154,7 @@ public override void Add(TestCategoryItem item)
EqtAssert.ParameterNotNull(item, nameof(item));

// Don't add empty items.
if (!String.IsNullOrEmpty(item.TestCategory))
if (!string.IsNullOrEmpty(item.TestCategory))
{
base.Add(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ internal string GetResultsDirectory()
if (RunConfiguration == null)
{
Debug.Fail("'RunConfiguration' is null");
throw new Exception(String.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_MissingRunConfigInRun));
throw new Exception(string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_MissingRunConfigInRun));
}

if (string.IsNullOrEmpty(RunConfiguration.RunDeploymentRootDirectory))
{
Debug.Fail("'RunConfiguration.RunDeploymentRootDirectory' is null or empty");
throw new Exception(String.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_MissingRunDeploymentRootInRunConfig));
throw new Exception(string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_MissingRunDeploymentRootInRunConfig));
}

return RunConfiguration.RunDeploymentInDirectory;
Expand All @@ -185,7 +185,7 @@ private static string FormatDateTimeForRunName(DateTime timeStamp)
private void Initialize()
{
_id = Guid.NewGuid();
_name = String.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_TestRunName, Environment.GetEnvironmentVariable("UserName"), Environment.MachineName, FormatDateTimeForRunName(DateTime.Now));
_name = string.Format(CultureInfo.CurrentCulture, TrxLoggerResources.Common_TestRunName, Environment.GetEnvironmentVariable("UserName"), Environment.MachineName, FormatDateTimeForRunName(DateTime.Now));

// Fix for issue (https://github.com/Microsoft/vstest/issues/213). Since there is no way to find current user in linux machine.
// We are catching PlatformNotSupportedException for non windows machine.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal class TestRunSummary : IXmlTestStore

private readonly List<CollectorDataEntry> _collectorDataEntries;

private readonly IList<String> _resultFiles;
private readonly IList<string> _resultFiles;

/// <summary>
/// Initializes a new instance of the <see cref="TestRunSummary"/> class.
Expand Down Expand Up @@ -97,7 +97,7 @@ public TestRunSummary(
TestOutcome outcome,
List<RunInfo> runMessages,
string stdOut,
IList<String> resultFiles,
IList<string> resultFiles,
List<CollectorDataEntry> dataCollectors)
{
_totalTests = total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ public List<CollectorDataEntry> ToCollectionEntries(IEnumerable<AttachmentSet> a
return collectorEntries;
}

public IList<String> ToResultFiles(IEnumerable<AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory,
public IList<string> ToResultFiles(IEnumerable<AttachmentSet> attachmentSets, TestRun testRun, string trxFileDirectory,
List<string> errorMessages)
{
List<String> resultFiles = new();
List<string> resultFiles = new();
if (attachmentSets == null)
{
return resultFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface IRunContext : IDiscoveryContext
/// It is used only with sources. With specific test cases it will always be null.
/// If there is a parsing error or filter expression has unsupported properties, TestPlatformFormatException() is thrown.
/// </summary>
ITestCaseFilterExpression GetTestCaseFilter(IEnumerable<String> supportedProperties, Func<string, TestProperty> propertyProvider);
ITestCaseFilterExpression GetTestCaseFilter(IEnumerable<string> supportedProperties, Func<string, TestProperty> propertyProvider);

/// <summary>
/// Directory which should be used for storing result files/deployment files etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static bool IsValidFileName(string fileName, out string invalidCharacters
{
if (InvalidFileNameChars.ContainsKey(fileName[i]))
{
invalidCharacters = String.Concat(invalidCharacters, fileName[i]);
invalidCharacters = string.Concat(invalidCharacters, fileName[i]);
result = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static DataCollectorSettings FromXml(XmlReader reader)
}
catch (UriFormatException)
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture, Resources.Resources.InvalidDataCollectorUriInSettings, reader.Value));
throw new SettingsException(string.Format(CultureInfo.CurrentCulture, Resources.Resources.InvalidDataCollectorUriInSettings, reader.Value));
}

break;
Expand All @@ -186,7 +186,7 @@ internal static DataCollectorSettings FromXml(XmlReader reader)

default:
throw new SettingsException(
String.Format(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsXmlAttribute,
Constants.DataCollectionRunSettingsName,
Expand All @@ -212,7 +212,7 @@ internal static DataCollectorSettings FromXml(XmlReader reader)

default:
throw new SettingsException(
String.Format(
string.Format(
CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsXmlElement,
Constants.DataCollectionRunSettingsName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestSessionStartArgs : InProcDataCollectionArgs
/// </summary>
public TestSessionStartArgs()
{
Configuration = String.Empty;
Configuration = string.Empty;
}

/// <summary>
Expand All @@ -31,7 +31,7 @@ public TestSessionStartArgs()
/// </param>
public TestSessionStartArgs(IDictionary<string, object> properties)
{
Configuration = String.Empty;
Configuration = string.Empty;
_properties = properties;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.TestPlatform.ObjectModel/ExceptionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel;
#endif
public class TestPlatformException : Exception
{
public TestPlatformException(String message)
public TestPlatformException(string message)
: base(message)
{
}
Expand Down Expand Up @@ -57,7 +57,7 @@ public static Exception ConvertException(FaultException faultEx)
/// <param name="innerException">actual exception that is to be wrapped</param>
/// <returns>actual exception that is represented by the exception name</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Instantiating an instance of Exception class")]
private static Exception ConvertException(String exceptionType, String message, Exception innerException)
private static Exception ConvertException(string exceptionType, string message, Exception innerException)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public static RunConfiguration FromXml(XmlReader reader)
bool bCollectSourceInformation = true;
if (!bool.TryParse(collectSourceInformationStr, out bCollectSourceInformation))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, bCollectSourceInformation, elementName));
}

Expand Down Expand Up @@ -666,7 +666,7 @@ public static RunConfiguration FromXml(XmlReader reader)
string designModeValueString = reader.ReadElementContentAsString();
if (!bool.TryParse(designModeValueString, out bool designMode))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, designModeValueString, elementName));
}
runConfiguration.DesignMode = designMode;
Expand All @@ -678,7 +678,7 @@ public static RunConfiguration FromXml(XmlReader reader)
string inIsolationValueString = reader.ReadElementContentAsString();
if (!bool.TryParse(inIsolationValueString, out bool inIsolation))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, inIsolationValueString, elementName));
}
runConfiguration.InIsolation = inIsolation;
Expand All @@ -690,7 +690,7 @@ public static RunConfiguration FromXml(XmlReader reader)
string disableAppDomainValueString = reader.ReadElementContentAsString();
if (!bool.TryParse(disableAppDomainValueString, out bool disableAppDomainCheck))
{
throw new SettingsException(String.Format(CultureInfo.CurrentCulture,
throw new SettingsException(string.Format(CultureInfo.CurrentCulture,
Resources.Resources.InvalidSettingsIncorrectValue, Constants.RunConfigurationSettingsName, disableAppDomainValueString, elementName));
}
runConfiguration.DisableAppDomain = disableAppDomainCheck;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public string[] GetReferencedAssemblies(string path)
public void GetPlatformAndFrameworkSettings(string path, out string procArchType, out string frameworkVersion)
{
procArchType = nameof(Architecture.Default);
frameworkVersion = String.Empty;
frameworkVersion = string.Empty;

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public static DataCollectionRunSettings GetInProcDataCollectionRunSettings(strin
/// </summary>
/// <param name="runSettings">The run Settings Xml.</param>
/// <returns> The <see cref="LoggerRunSettings"/>. </returns>
public static LoggerRunSettings GetLoggerRunSettings(String runSettings)
public static LoggerRunSettings GetLoggerRunSettings(string runSettings)
{
return GetNodeValue(
runSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public static void UpdateTargetPlatform(XmlDocument runSettingsDocument, string
AddNodeIfNotPresent(runSettingsDocument, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite);
}

public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, out String deviceXml)
public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, out string deviceXml)
{
ValidateArg.NotNull(runSettingsNavigator, nameof(runSettingsNavigator));

Expand Down Expand Up @@ -630,10 +630,10 @@ public static bool TryGetFrameworkXml(XPathNavigator runSettingsNavigator, out s
/// Returns the sources matching the specified platform and framework settings.
/// For incompatible sources, warning is added to incompatibleSettingWarning.
/// </summary>
public static IEnumerable<String> FilterCompatibleSources(Architecture chosenPlatform, Architecture defaultArchitecture, Framework chosenFramework, IDictionary<String, Architecture> sourcePlatforms, IDictionary<String, Framework> sourceFrameworks, out String incompatibleSettingWarning)
public static IEnumerable<string> FilterCompatibleSources(Architecture chosenPlatform, Architecture defaultArchitecture, Framework chosenFramework, IDictionary<string, Architecture> sourcePlatforms, IDictionary<string, Framework> sourceFrameworks, out string incompatibleSettingWarning)
{
incompatibleSettingWarning = string.Empty;
List<String> compatibleSources = new();
List<string> compatibleSources = new();
StringBuilder warnings = new();
warnings.AppendLine();
bool incompatiblityFound = false;
Expand Down
12 changes: 6 additions & 6 deletions src/vstest.console/CommandLine/CommandArgumentPair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ internal class CommandArgumentPair
/// <param name="input">Input to break up.</param>
public CommandArgumentPair(string input)
{
if (String.IsNullOrWhiteSpace(input))
if (string.IsNullOrWhiteSpace(input))
{
throw new ArgumentException(CommandLineResources.CannotBeNullOrEmpty, nameof(input));
}
Contract.Ensures(!String.IsNullOrWhiteSpace(Command));
Contract.Ensures(!string.IsNullOrWhiteSpace(Command));

Parse(input);
}
Expand All @@ -53,7 +53,7 @@ public CommandArgumentPair(string input)
/// <param name="argument">The argument portion of the input.</param>
public CommandArgumentPair(string command, string argument)
{
if (String.IsNullOrWhiteSpace(command))
if (string.IsNullOrWhiteSpace(command))
{
throw new ArgumentException(CommandLineResources.CannotBeNullOrEmpty, nameof(command));
}
Expand All @@ -71,8 +71,8 @@ public CommandArgumentPair(string command, string argument)
/// <param name="input">Input string to parse.</param>
private void Parse(string input)
{
Contract.Requires(!String.IsNullOrWhiteSpace(input));
Contract.Ensures(!String.IsNullOrWhiteSpace(Command));
Contract.Requires(!string.IsNullOrWhiteSpace(input));
Contract.Ensures(!string.IsNullOrWhiteSpace(Command));
Contract.Ensures(Argument != null);

// Find the index of the separator (":")
Expand All @@ -82,7 +82,7 @@ private void Parse(string input)
{
// No separator was found, so use the input as the command.
Command = input;
Argument = String.Empty;
Argument = string.Empty;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/vstest.console/CommandLine/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ internal Framework TargetFrameworkVersion
/// <param name="source">Path to source file to look for tests in.</param>
public void AddSource(string source)
{
if (String.IsNullOrWhiteSpace(source))
if (string.IsNullOrWhiteSpace(source))
{
throw new TestSourceException(CommandLineResources.CannotBeNullOrEmpty);
}
Expand Down
Loading