mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-01 10:25:36 +00:00
Front end for uploading a release asset.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
@@ -24,6 +26,36 @@ namespace Octokit
|
||||
return new Uri(string.Format(CultureInfo.InvariantCulture, pattern, args), UriKind.Relative);
|
||||
}
|
||||
|
||||
static Regex OptionalQueryStringRegex = new Regex("\\{\\?([^}]+)\\}");
|
||||
public static Uri ExpandUriTemplate(this string template, object values)
|
||||
{
|
||||
var optionalQueryStringMatch = OptionalQueryStringRegex.Match(template);
|
||||
if(optionalQueryStringMatch.Success)
|
||||
{
|
||||
var expansion = "";
|
||||
var parameterName = optionalQueryStringMatch.Groups[1].Value;
|
||||
var parameterProperty = values.GetType().GetProperty(parameterName);
|
||||
if(parameterProperty != null)
|
||||
{
|
||||
expansion = "?" + parameterName + "=" + Uri.EscapeDataString("" + parameterProperty.GetValue(values, new object[0]));
|
||||
}
|
||||
template = OptionalQueryStringRegex.Replace(template, expansion);
|
||||
}
|
||||
return new Uri(template);
|
||||
}
|
||||
|
||||
#if NETFX_CORE
|
||||
public static PropertyInfo GetProperty(this Type t, string propertyName)
|
||||
{
|
||||
return t.GetTypeInfo().GetDeclaredProperty(propertyName);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static string EscapeUri(this string s)
|
||||
{
|
||||
return Uri.EscapeUriString(s);
|
||||
}
|
||||
|
||||
// :trollface:
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
|
||||
Justification = "Ruby don't care. Ruby don't play that.")]
|
||||
|
||||
Reference in New Issue
Block a user