Skip to content

Commit

Permalink
Merge pull request #882 from ronaldbarendse/feature/cloudbuildallvars…
Browse files Browse the repository at this point in the history
…-formatting

Fix CloudBuildAllVars value formatting
  • Loading branch information
AArnott committed Jan 20, 2023
2 parents 69e414b + 4f415c1 commit 175cea8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/NerdBank.GitVersioning/VersionOracle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public IEnumerable<string> BuildMetadataWithCommitId
/// <summary>
/// Gets the version options used to initialize this instance.
/// </summary>
[Ignore]
public VersionOptions? VersionOptions { get; }

/// <summary>
Expand Down Expand Up @@ -296,17 +297,27 @@ public IEnumerable<string> BuildMetadataWithCommitId
{
var variables = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

PropertyInfo[]? properties = this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
foreach (PropertyInfo? property in properties)
PropertyInfo[] properties = this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance);
foreach (PropertyInfo property in properties)
{
if (property.GetCustomAttribute<IgnoreAttribute>() is null)
if (property.GetCustomAttribute<IgnoreAttribute>() is not null)
{
continue;
}

object? propertyValue = property.GetValue(this);
if (propertyValue is null)
{
object? value = property.GetValue(this);
if (value is object)
{
variables.Add($"NBGV_{property.Name}", value.ToString() ?? string.Empty);
}
continue;
}

string value = propertyValue switch
{
DateTimeOffset dateTimeOffset => dateTimeOffset.ToString("o", CultureInfo.InvariantCulture),
_ => Convert.ToString(propertyValue, CultureInfo.InvariantCulture) ?? string.Empty,
};

variables.Add($"NBGV_{property.Name}", value);
}

return variables;
Expand Down

0 comments on commit 175cea8

Please sign in to comment.