Skip to content

Instantly share code, notes, and snippets.

@darrelmiller
Created April 1, 2015 16:11
Show Gist options
  • Save darrelmiller/deff3525791be6470520 to your computer and use it in GitHub Desktop.
Save darrelmiller/deff3525791be6470520 to your computer and use it in GitHub Desktop.
public class TavisUriTemplateHandler : IUrlTemplateHandler
{
public IEnumerable<string> GetParameterNames(string template)
{
return new UriTemplate(template).GetParameterNames();
}
public Uri GetRequestUri(IUrlParameterFormatter urlParameterFormatter, RestMethodInfo restMethod, object[] paramList, string basePath = "")
{
string urlTarget = (basePath == "/" ? String.Empty : basePath) + restMethod.RelativePath;
var template = new UriTemplate(urlTarget);
for (int i = 0; i < paramList.Length; i++)
{
if (restMethod.ParameterMap.ContainsKey(i))
{
template.AddParameter(restMethod.ParameterMap[i], urlParameterFormatter.Format(paramList[i], restMethod.ParameterInfoMap[i]));
}
}
return new Uri(template.Resolve(), UriKind.RelativeOrAbsolute);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment