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

deconstruct some KeyValuePair #4573

Merged
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 @@ -513,15 +513,15 @@ private void ExecuteTestsWithTestRunner(
var testContextProperties = new Dictionary<string, object?>(capacity: 8);

// Add tcm properties.
foreach (KeyValuePair<TestProperty, object?> propertyPair in tcmProperties)
foreach ((TestProperty key, object? value) in tcmProperties)
{
testContextProperties[propertyPair.Key.Id] = propertyPair.Value;
testContextProperties[key.Id] = value;
}

// Add source level parameters.
foreach (KeyValuePair<string, object> propertyPair in sourceLevelParameters)
foreach ((string key, object value) in sourceLevelParameters)
{
testContextProperties[propertyPair.Key] = propertyPair.Value;
testContextProperties[key] = value;
}

return testContextProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ private static List<DeploymentItem> GetDeploymentItems(IEnumerable deploymentIte

IList<DeploymentItem> result = new List<DeploymentItem>();

foreach (KeyValuePair<string, string> deploymentItemData in deploymentItemsData)
foreach ((string? key, string? value) in deploymentItemsData)
{
AddDeploymentItem(result, new DeploymentItem(deploymentItemData.Key, deploymentItemData.Value));
AddDeploymentItem(result, new DeploymentItem(key, value));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ internal Dictionary<K, ImmutableArray<T>> ToDictionary<K>(Func<T, K> keySelector
var dictionary = new Dictionary<K, ImmutableArray<T>>(accumulator.Count, comparer);

// freeze
foreach (KeyValuePair<K, ArrayBuilder<T>> pair in accumulator)
foreach ((K? key, ArrayBuilder<T>? value) in accumulator)
{
dictionary.Add(pair.Key, pair.Value.ToImmutableAndFree());
dictionary.Add(key, value.ToImmutableAndFree());
}

return dictionary;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ private async Task IngestLoopAsync()
{
StringBuilder builder = new();
builder.AppendLine(CultureInfo.InvariantCulture, $"Send telemetry event: {eventName}");
foreach (KeyValuePair<string, string> keyValue in properties)
foreach ((string key, string value) in properties)
{
builder.AppendLine(CultureInfo.InvariantCulture, $" {keyValue.Key}: {keyValue.Value}");
builder.AppendLine(CultureInfo.InvariantCulture, $" {key}: {value}");
}

foreach (KeyValuePair<string, double> keyValue in metrics)
foreach ((string key, double value) in metrics)
{
builder.AppendLine(CultureInfo.InvariantCulture, $" {keyValue.Key}: {keyValue.Value.ToString("f", CultureInfo.InvariantCulture)}");
builder.AppendLine(CultureInfo.InvariantCulture, $" {key}: {value.ToString("f", CultureInfo.InvariantCulture)}");
}

await _logger.LogTraceAsync(builder.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ public override async Task DrainDataAsync()
StringBuilder builder = new();
builder.Append(CultureInfo.InvariantCulture, $"Publisher/Consumer loop detected during the drain after {stopwatch.Elapsed}.\n{builder}");

foreach (KeyValuePair<AsyncConsumerDataProcessor, long> keyValuePair in consumerToDrain)
foreach ((AsyncConsumerDataProcessor key, long value) in consumerToDrain)
{
builder.AppendLine(CultureInfo.InvariantCulture, $"Consumer '{keyValuePair.Key.DataConsumer}' payload received {keyValuePair.Value}.");
builder.AppendLine(CultureInfo.InvariantCulture, $"Consumer '{key.DataConsumer}' payload received {value}.");
}

throw new InvalidOperationException(builder.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public void Serialize(object objectToSerialize, Stream stream)
}

WriteShort(stream, (ushort)handshakeMessage.Properties.Count);
foreach (KeyValuePair<byte, string> property in handshakeMessage.Properties)
foreach ((byte key, string value) in handshakeMessage.Properties)
{
WriteField(stream, property.Key);
WriteField(stream, property.Value);
WriteField(stream, key);
WriteField(stream, value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ static SerializerUtilities()
properties[namedKvpStringProperty.Name] = namedKvpStringProperty.Pairs;
#else
JsonArray collection = [];
foreach (KeyValuePair<string, string> item in namedKvpStringProperty.Pairs)
foreach ((string? key, string? value) in namedKvpStringProperty.Pairs)
{
JsonObject o = new()
{
{ item.Key, item.Value },
{ key, value },
};
collection.Add(o);
}
Expand Down Expand Up @@ -420,11 +420,11 @@ static SerializerUtilities()
values[JsonRpcStrings.EnvironmentVariables] = ev.EnvironmentVariables;
#else
JsonArray collection = [];
foreach (KeyValuePair<string, string?> item in ev.EnvironmentVariables)
foreach ((string? key, string? value) in ev.EnvironmentVariables)
{
JsonObject o = new()
{
{ item.Key, item.Value },
{ key, value },
};
collection.Add(o);
}
Expand Down Expand Up @@ -624,17 +624,17 @@ static SerializerUtilities()
string displayName = string.Empty;
PropertyBag propertyBag = new();

foreach (KeyValuePair<string, object?> p in properties)
foreach ((string? key, object? value) in properties)
{
if (p.Key == JsonRpcStrings.Uid)
if (key == JsonRpcStrings.Uid)
{
uid = p.Value as string ?? string.Empty;
uid = value as string ?? string.Empty;
continue;
}

if (p.Key == JsonRpcStrings.DisplayName)
if (key == JsonRpcStrings.DisplayName)
{
displayName = p.Value as string ?? string.Empty;
displayName = value as string ?? string.Empty;
continue;
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/Performance/MSTest.Performance.Runner/PipelinesRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public int Run(string pipelineNameFilter, IDictionary<string, object>? parameter
{ "PipelineName", pipeline.PipelineName },
};

foreach (KeyValuePair<string, object> item in parametersBag)
foreach ((string key, object value) in parametersBag)
{
pipelinePropertyBag.Add(item.Key, item.Value);
pipelinePropertyBag.Add(key, value);
}

pipeline.UpdatePropertyBag?.Invoke(pipelinePropertyBag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public async Task<int> ExecuteAsync(
}

IDictionary<string, string?> mergedEnvironmentVariables = new Dictionary<string, string?>(environmentVariables1);
foreach (KeyValuePair<string, string?> kvp in environmentVariables2)
foreach ((string key, string? value) in environmentVariables2)
{
mergedEnvironmentVariables[kvp.Key] = kvp.Value;
mergedEnvironmentVariables[key] = value;
}

return mergedEnvironmentVariables;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public static IProcessHandle Start(ProcessConfiguration config, bool cleanDefaul
processStartInfo.EnvironmentVariables.Clear();
}

foreach (KeyValuePair<string, string?> kvp in config.EnvironmentVariables)
foreach ((string key, string? value) in config.EnvironmentVariables)
{
if (kvp.Value is null)
if (value is null)
{
continue;
}

processStartInfo.EnvironmentVariables[kvp.Key] = kvp.Value;
processStartInfo.EnvironmentVariables[key] = value;
}
}

Expand Down