Skip to content
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
25 changes: 9 additions & 16 deletions src/Microsoft.PowerShell.ScheduledJob/ScheduledJobStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ public static FileStream GetFileForJobDefinition(
throw new PSArgumentException("definitionPath");
}

string filePathName = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}\{2}.xml",
definitionPath, definitionName, DefinitionFileName);
string filePathName = string.Create(CultureInfo.InvariantCulture, $@"{definitionPath}\{definitionName}\{DefinitionFileName}.xml");
return File.Open(filePathName, fileMode, fileAccess, fileShare);
}

Expand Down Expand Up @@ -483,7 +482,7 @@ private static string CreateFilePathName(string definitionName, string fileName)

Directory.CreateDirectory(filePath);
Directory.CreateDirectory(outputPath);
return string.Format(CultureInfo.InstalledUICulture, @"{0}\{1}.xml", filePath, fileName);
return string.Create(CultureInfo.InstalledUICulture, $@"{filePath}\{fileName}.xml");
}

/// <summary>
Expand All @@ -495,7 +494,7 @@ private static string CreateFilePathName(string definitionName, string fileName)
private static string GetFilePathName(string definitionName, string fileName)
{
string filePath = GetJobDefinitionPath(definitionName);
return string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.xml", filePath, fileName);
return string.Create(CultureInfo.InvariantCulture, $@"{filePath}\{fileName}.xml");
}

/// <summary>
Expand Down Expand Up @@ -525,8 +524,7 @@ private static string GetRunDirectory(
DateTime runStart)
{
string directoryPath = GetJobRunOutputDirectory(definitionName);
return string.Format(CultureInfo.InvariantCulture, @"{0}\{1}", directoryPath,
ConvertDateTimeToJobRunName(runStart));
return string.reate(CultureInfo.InvariantCulture, $@"{directoryPath}\{ConvertDateTimeToJobRunName(runStart)}");
}

/// <summary>
Expand All @@ -540,8 +538,7 @@ private static string GetRunDirectoryFromPath(
string definitionOutputPath,
DateTime runStart)
{
return string.Format(CultureInfo.InvariantCulture, @"{0}\{1}",
definitionOutputPath, ConvertDateTimeToJobRunName(runStart));
return string.Create(CultureInfo.InvariantCulture, $@"{definitionOutputPath}\{ConvertDateTimeToJobRunName(runStart)}");
}

/// <summary>
Expand All @@ -558,11 +555,9 @@ private static string GetRunFilePathName(
DateTime runStart)
{
string directoryPath = GetJobRunOutputDirectory(definitionName);
string jobRunPath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}",
directoryPath, ConvertDateTimeToJobRunName(runStart));
string jobRunPath = string.Create(CultureInfo.InvariantCulture, $@"{directoryPath}\{ConvertDateTimeToJobRunName(runStart)}");

return string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.xml", jobRunPath,
runItem.ToString());
return string.Create(CultureInfo.InvariantCulture, $@"{jobRunPath}\{runItem}.xml");
}

/// <summary>
Expand All @@ -579,17 +574,15 @@ private static string GetRunFilePathNameFromPath(
JobRunItem runItem,
DateTime runStart)
{
string jobRunPath = string.Format(CultureInfo.InvariantCulture, @"{0}\{1}",
outputPath, ConvertDateTimeToJobRunName(runStart));
string jobRunPath = string.Create(CultureInfo.InvariantCulture, $@"{outputPath}\{ConvertDateTimeToJobRunName(runStart)}");

if (!Directory.Exists(jobRunPath))
{
// Create directory for this job run date.
Directory.CreateDirectory(jobRunPath);
}

return string.Format(CultureInfo.InvariantCulture, @"{0}\{1}.xml", jobRunPath,
runItem.ToString());
return string.Create(CultureInfo.InvariantCulture, $@"{jobRunPath}\{runItem}.xml");
}

private static void AddFullAccessToDirectory(
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.WSMan.Management/WsManHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ internal static void LoadResourceData()
#if CORECLR
"0409" /* TODO: don't assume it is always English on CSS? */
#else
string.Concat("0", string.Format(CultureInfo.CurrentCulture, "{0:x2}", checked((uint)CultureInfo.CurrentUICulture.LCID)))
string.Concat("0", string.Create(CultureInfo.CurrentCulture, $"{checked((uint)CultureInfo.CurrentUICulture.LCID):x2}"))
#endif
+ "\\" + "winrm.ini";
if (File.Exists(filepath))
Expand Down
30 changes: 15 additions & 15 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ public static void ClearCache()
/// <returns></returns>
private static string GetModuleQualifiedResourceName(string moduleName, string moduleVersion, string className, string resourceName)
{
return string.Format(CultureInfo.InvariantCulture, "{0}\\{1}\\{2}\\{3}", moduleName, moduleVersion, className, resourceName);
return string.Create(CultureInfo.InvariantCulture, $"{moduleName}\\{moduleVersion}\\{className}\\{resourceName}");
}

/// <summary>
Expand Down Expand Up @@ -1125,7 +1125,7 @@ private static List<DscClassCacheEntry> GetCachedClasses()
public static List<Microsoft.Management.Infrastructure.CimClass> GetCachedClassesForModule(PSModuleInfo module)
{
List<Microsoft.Management.Infrastructure.CimClass> cachedClasses = new();
var moduleQualifiedName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", module.Name, module.Version.ToString());
var moduleQualifiedName = string.Create(CultureInfo.InvariantCulture, $"{module.Name}\\{module.Version}");
foreach (var dscClassCacheEntry in ClassCache)
{
if (dscClassCacheEntry.Key.StartsWith(moduleQualifiedName, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -2019,7 +2019,7 @@ public static void LoadResourcesFromModule(IScriptExtent scriptExtent,
{
string moduleString = moduleToImport.Version == null
? moduleToImport.Name
: string.Format(CultureInfo.CurrentCulture, "<{0}, {1}>", moduleToImport.Name, moduleToImport.Version);
: string.Create(CultureInfo.CurrentCulture, $"<{moduleToImport.Name}, {moduleToImport.Version}>");

errorList.Add(new ParseError(scriptExtent, "ModuleNotFoundDuringParse",
string.Format(CultureInfo.CurrentCulture, ParserStrings.ModuleNotFoundDuringParse, moduleString)));
Expand Down Expand Up @@ -2339,7 +2339,7 @@ internal static string MapTypeNameToMofType(ITypeName typeName, string memberNam
private static void GenerateMofForAst(TypeDefinitionAst typeAst, StringBuilder sb, List<object> embeddedInstanceTypes)
{
var className = typeAst.Name;
sb.AppendFormat(CultureInfo.InvariantCulture, "[ClassVersion(\"1.0.0\"), FriendlyName(\"{0}\")]\nclass {0}", className);
sb.AppendFormat(CultureInfo.InvariantCulture, $"[ClassVersion(\"1.0.0\"), FriendlyName(\"{className}\")]\nclass {className}");

if (typeAst.Attributes.Any(static a => a.TypeName.GetReflectionAttributeType() == typeof(DscResourceAttribute)))
{
Expand Down Expand Up @@ -2912,19 +2912,19 @@ private static string MapAttributesToMof(string[] enumNames, IEnumerable<object>
{
if (dscProperty.Key)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}key", needComma ? ", " : string.Empty);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}key");
needComma = true;
}

if (dscProperty.Mandatory)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}required", needComma ? ", " : string.Empty);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}required");
needComma = true;
}

if (dscProperty.NotConfigurable)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}read", needComma ? ", " : string.Empty);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}read");
needComma = true;
}

Expand All @@ -2936,13 +2936,13 @@ private static string MapAttributesToMof(string[] enumNames, IEnumerable<object>
{
bool valueMapComma = false;
StringBuilder sbValues = new(", Values{");
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueMap{{", needComma ? ", " : string.Empty);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}ValueMap{{");
needComma = true;

foreach (var value in validateSet.ValidValues)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}\"{1}\"", valueMapComma ? ", " : string.Empty, value);
sbValues.AppendFormat(CultureInfo.InvariantCulture, "{0}\"{1}\"", valueMapComma ? ", " : string.Empty, value);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(valueMapComma ? ", " : string.Empty)}\"{value}\"");
sbValues.AppendFormat(CultureInfo.InvariantCulture, $"{(valueMapComma ? ", " : string.Empty)}\"{value}\"");
valueMapComma = true;
}

Expand All @@ -2961,27 +2961,27 @@ private static string MapAttributesToMof(string[] enumNames, IEnumerable<object>

if (enumNames != null)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}ValueMap{{", needComma ? ", " : string.Empty);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}ValueMap{{");
needComma = false;
foreach (var name in enumNames)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}\"{1}\"", needComma ? ", " : string.Empty, name);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}\"{name}\"");
needComma = true;
}

sb.Append("}, Values{");
needComma = false;
foreach (var name in enumNames)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}\"{1}\"", needComma ? ", " : string.Empty, name);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}\"{name}\"");
needComma = true;
}

sb.Append('}');
}
else if (embeddedInstanceType != null)
{
sb.AppendFormat(CultureInfo.InvariantCulture, "{0}EmbeddedInstance(\"{1}\")", needComma ? ", " : string.Empty, embeddedInstanceType);
sb.AppendFormat(CultureInfo.InvariantCulture, $"{(needComma ? ", " : string.Empty)}EmbeddedInstance(\"{embeddedInstanceType}\")");
}

sb.Append(']');
Expand Down Expand Up @@ -3047,7 +3047,7 @@ private static void GenerateMofForType(Type type, StringBuilder sb, List<object>
{
var className = type.Name;
// Friendly name is required by module validator to verify resource instance against the exclusive resource name list.
sb.AppendFormat(CultureInfo.InvariantCulture, "[ClassVersion(\"1.0.0\"), FriendlyName(\"{0}\")]\nclass {0}", className);
sb.AppendFormat(CultureInfo.InvariantCulture, $"[ClassVersion(\"1.0.0\"), FriendlyName(\"{className}\")]\nclass {className}");

if (type.GetCustomAttributes<DscResourceAttribute>().Any())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected FormatTableLoadException(SerializationInfo info, StreamingContext cont
_errors = new Collection<string>();
for (int index = 0; index < errorCount; index++)
{
string key = string.Format(CultureInfo.InvariantCulture, "Error{0}", index);
string key = string.Create(CultureInfo.InvariantCulture, $"Error{index}");
_errors.Add(info.GetString(key));
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont

for (int index = 0; index < errorCount; index++)
{
string key = string.Format(CultureInfo.InvariantCulture, "Error{0}", index);
string key = string.Create(CultureInfo.InvariantCulture, $"Error{index}");
info.AddValue(key, _errors[index]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,14 +490,12 @@ private static void TraceHelper(ViewDefinition vd, bool isMatched)
sb.Append(isMatched ? "MATCH FOUND" : "NOT MATCH");
if (tr != null)
{
sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1} TYPE: {2}",
ControlBase.GetControlShapeName(vd.mainControl), vd.name, tr.name);
sb.AppendFormat(CultureInfo.InvariantCulture, $" {ControlBase.GetControlShapeName(vd.mainControl)} NAME: {vd.name} TYPE: {tr.name}");
}
else
{
TypeGroupReference tgr = togr as TypeGroupReference;
sb.AppendFormat(CultureInfo.InvariantCulture, " {0} NAME: {1} GROUP: {2}",
ControlBase.GetControlShapeName(vd.mainControl), vd.name, tgr.name);
sb.AppendFormat(CultureInfo.InvariantCulture, $" {ControlBase.GetControlShapeName(vd.mainControl)} NAME: {vd.name} GROUP: {tgr.name}");
}

ActiveTracer.WriteLine(sb.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ private static string GetCmdletAttributes(CommonCmdletMetadata cmdletMetadata)
? ("'" + CodeGeneration.EscapeSingleQuotedStringContent(cmdletMetadata.Obsolete.Message) + "'")
: string.Empty;
string newline = (attributes.Length > 0) ? Environment.NewLine : string.Empty;
attributes.AppendFormat(CultureInfo.InvariantCulture, "{0}[Obsolete({1})]", newline, obsoleteMsg);
attributes.AppendFormat(CultureInfo.InvariantCulture, $"{newline}[Obsolete({obsoleteMsg})]");
}

return attributes.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,12 @@ protected Exception CreateUnknownNodeException()

protected Exception CreateUnknownTypeException(XmlQualifiedName type)
{
return new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "XmlUnknownType. Name: {0}, Namespace {1}, CurrentTag: {2}", type.Name, type.Namespace, CurrentTag()));
return new InvalidOperationException(string.Create(CultureInfo.CurrentCulture, $"XmlUnknownType. Name: {type.Name}, Namespace {type.Namespace}, CurrentTag: {CurrentTag()}"));
}

protected Exception CreateUnknownConstantException(string value, Type enumType)
{
return new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "XmlUnknownConstant. Value: {0}, EnumType: {1}", value, enumType.Name));
return new InvalidOperationException(string.Create(CultureInfo.CurrentCulture, $"XmlUnknownConstant. Value: {value}, EnumType: {enumType.Name}"));
}

protected Array ShrinkArray(Array a, int length, Type elementType, bool isNullable)
Expand Down Expand Up @@ -426,7 +426,7 @@ internal XmlQualifiedName ToXmlQualifiedName(string value, bool decodeName)
if (ns == null)
{
// Namespace prefix '{0}' is not defined.
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "XmlUndefinedAlias. Prefix: {0}", prefix));
throw new InvalidOperationException(string.Create(CultureInfo.CurrentCulture, $"XmlUndefinedAlias. Prefix: {prefix}"));
}

return new XmlQualifiedName(_r.NameTable.Add(localName), ns);
Expand Down