mirror of
https://github.com/actions/runner.git
synced 2025-12-18 16:26:58 +00:00
Support downloading/publishing artifacts from Pipelines endpoint (#188)
* Support downloading/publishing artifacts from Pipelines endpoint * Remove `Path` from everywhere * Remove unused JobId argument * PR feedback * More PR feedback
This commit is contained in:
45
src/Sdk/PipelinesWebApi/UnknownEnum.cs
Normal file
45
src/Sdk/PipelinesWebApi/UnknownEnum.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace GitHub.Actions.Pipelines.WebApi
|
||||
{
|
||||
public static class UnknownEnum
|
||||
{
|
||||
public static T Parse<T>(string stringValue)
|
||||
{
|
||||
return (T)Parse(typeof(T), stringValue);
|
||||
}
|
||||
|
||||
public static object Parse(Type enumType, string stringValue)
|
||||
{
|
||||
var underlyingType = Nullable.GetUnderlyingType(enumType);
|
||||
enumType = underlyingType != null ? underlyingType : enumType;
|
||||
|
||||
var names = Enum.GetNames(enumType);
|
||||
if (!string.IsNullOrEmpty(stringValue))
|
||||
{
|
||||
var match = names.FirstOrDefault(name => string.Equals(name, stringValue, StringComparison.OrdinalIgnoreCase));
|
||||
if (match != null)
|
||||
{
|
||||
return Enum.Parse(enumType, match);
|
||||
}
|
||||
|
||||
// maybe we have an enum member with an EnumMember attribute specifying a custom name
|
||||
foreach (var field in enumType.GetFields())
|
||||
{
|
||||
var enumMemberAttribute = field.GetCustomAttributes(typeof(EnumMemberAttribute), false).FirstOrDefault() as EnumMemberAttribute;
|
||||
if (enumMemberAttribute != null && string.Equals(enumMemberAttribute.Value, stringValue, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// we already have the field, no need to do enum.parse on it
|
||||
return field.GetValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Enum.Parse(enumType, UnknownName);
|
||||
}
|
||||
|
||||
private const string UnknownName = "Unknown";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user