Skip to content
Merged
Changes from 1 commit
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
29 changes: 21 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,29 @@ public IDictionary<string, string> CloudBuildAllVars
{
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;
}

const string isoDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";

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

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

return variables;
Expand Down