Front end for uploading a release asset.

This commit is contained in:
Matt Burke
2013-10-02 14:55:05 -04:00
committed by Haacked
parent 9a6e46d608
commit 15a5cc9591
8 changed files with 124 additions and 0 deletions
+32
View File
@@ -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.")]