Skip to content

Instantly share code, notes, and snippets.

@brainwipe
Last active June 21, 2017 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainwipe/845a24fe773186b318a91e51b8b2a916 to your computer and use it in GitHub Desktop.
Save brainwipe/845a24fe773186b318a91e51b8b2a916 to your computer and use it in GitHub Desktop.
A .NET 4.6.2 one page console app for exploring the parts of a Uri class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UriExplorer
{
class Program
{
// Inspired by https://www.dotnetperls.com/uri
static void Main(string[] args)
{
var uri = new Uri("https://github.com/brainwipe/NJsonApiCore/search?utf8=%E2%9C%93&q=jsonapi&type=");
Uri segmentToMatch = null;
if (args.Length > 0)
{
if (args[0] == "-h" || args[0] == "-help")
{
Console.WriteLine("Use: uriexplorer [Url] [Segment to match]");
Console.WriteLine("Example: uriexplorer http://www.google.com http://www.google");
return;
}
uri = new Uri(args[0]);
if (args.Length == 2)
{
segmentToMatch = new Uri(args[1]);
}
}
Console.WriteLine($"Uri parts for: {uri}");
Console.WriteLine($"(-h for help)");
Print(uri, segmentToMatch);
}
static void Print(Uri uri, Uri segment)
{
// Print properties of Uri instance.
Console.WriteLine($"AbsolutePath\t\t{uri.AbsolutePath}");
Console.WriteLine($"AbsoluteUri\t\t{uri.AbsoluteUri}");
Console.WriteLine($"Authority\t\t{uri.Authority}");
Console.WriteLine($"DnsSafeHost\t\t{uri.DnsSafeHost}");
Console.WriteLine($"Fragment\t\t{uri.Fragment}");
Console.WriteLine($"Host\t\t\t{uri.Host}");
Console.WriteLine($"HostNameType\t\t{uri.HostNameType}");
Console.WriteLine($"IsAbsoluteUri\t\t{uri.IsAbsoluteUri}");
Console.WriteLine($"IsDefaultPort\t\t{uri.IsDefaultPort}");
Console.WriteLine($"IsFile\t\t\t{uri.IsFile}");
Console.WriteLine($"IsLoopback\t\t{uri.IsLoopback}");
Console.WriteLine($"IsUnc\t\t\t{uri.IsUnc}");
Console.WriteLine($"LocalPath\t\t{uri.LocalPath}");
Console.WriteLine($"OriginalString\t\t{uri.OriginalString}");
Console.WriteLine($"PathAndQuery\t\t{uri.PathAndQuery}");
Console.WriteLine($"Port\t\t\t{uri.Port}");
Console.WriteLine($"Query\t\t\t{uri.Query}");
Console.WriteLine($"Scheme\t\t\t{uri.Scheme}");
Console.WriteLine($"Segments\t\t{string.Join(" ", uri.Segments)}");
Console.WriteLine($"UserEscaped\t\t{uri.UserEscaped}");
Console.WriteLine($"UserInfo\t\t{uri.UserInfo}");
if (segment != null)
{
Console.WriteLine($"IsBaseOf()\t\t{uri.IsBaseOf(segment)}");
}
Console.WriteLine(new string('-', 40));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment