public static bool TryFrom(string value, out HttpLink link) { link = null; var schemeParts = value.Split(new[] { Uri.SchemeDelimiter }, StringSplitOptions.None); if (schemeParts.Length == 2) { var pathSeparatorIndex = schemeParts[1].IndexOf('/'); if (pathSeparatorIndex == -1 || pathSeparatorIndex == schemeParts[1].Length - 1) { if (HttpHost.TryFrom(value, out var parsedHost)) { link = new HttpLink(parsedHost, HttpResource.Root); } } else { var hostText = schemeParts[0] + Uri.SchemeDelimiter + schemeParts[1].Substring(0, pathSeparatorIndex); var resourceText = schemeParts[1].Substring(pathSeparatorIndex + 1); if (HttpHost.TryFrom(hostText, out var parsedHost)) { if (HttpResource.TryFrom(resourceText, out var parsedResource)) { link = new HttpLink(parsedHost, parsedResource); } } } } return(link != null); }
public static bool TryFrom(string host, string resource, out HttpLink link) { link = null; if (HttpHost.TryFrom(host, out var parsedHost)) { if (HttpResource.TryFrom(resource, out var parsedResource)) { link = new HttpLink(parsedHost, parsedResource); } } return(link != null); }
public static bool TryFrom(string value, out Href href) { if (HttpLink.TryFrom(value, out var link)) { href = link; } else if (HttpResource.TryFrom(value, out var resource)) { href = resource; } else { href = null; } return(href != null); }
// // Factory // public static bool TryFrom(HttpHost host, string resource, out HttpLink link) { link = HttpResource.TryFrom(resource, out var parsedResource) ? new HttpLink(host, parsedResource) : null; return(link != null); }