mirror of
https://github.com/actions/runner.git
synced 2025-12-14 04:53:34 +00:00
30 lines
872 B
C#
30 lines
872 B
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Globalization;
|
|
using System.Reflection;
|
|
|
|
namespace GitHub.Services.Common
|
|
{
|
|
/// <summary>
|
|
/// Utility class for wrapping Convert.ChangeType to handle nullable values.
|
|
/// </summary>
|
|
public class ConvertUtility
|
|
{
|
|
public static object ChangeType(object value, Type type)
|
|
{
|
|
return ChangeType(value, type, CultureInfo.CurrentCulture);
|
|
}
|
|
|
|
public static object ChangeType(object value, Type type, IFormatProvider provider)
|
|
{
|
|
if (type.IsOfType(typeof(Nullable<>)))
|
|
{
|
|
var nullableConverter = new NullableConverter(type);
|
|
return nullableConverter.ConvertTo(value, nullableConverter.UnderlyingType);
|
|
}
|
|
|
|
return Convert.ChangeType(value, type, provider);
|
|
}
|
|
}
|
|
}
|