Files
ICD.Common.Utils/ICD.Common.Utils/Extensions/UriExtensions.cs
2019-11-07 19:22:52 -05:00

51 lines
1.2 KiB
C#

using System;
using System.Linq;
using ICD.Common.Properties;
namespace ICD.Common.Utils.Extensions
{
public static class UriExtensions
{
/// <summary>
/// Gets the username from the given URI.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
[NotNull]
public static string GetUserName([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.UserInfo.Split(':').FirstOrDefault(string.Empty);
}
/// <summary>
/// Gets the password from the given URI.
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
[NotNull]
public static string GetPassword([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.UserInfo.Split(':').Skip(1).FirstOrDefault(string.Empty);
}
/// <summary>
/// Returns true if the URI matches the default http://localhost/
/// </summary>
/// <param name="extends"></param>
/// <returns></returns>
public static bool GetIsDefault([NotNull] this Uri extends)
{
if (extends == null)
throw new ArgumentNullException("extends");
return extends.ToString() == "http://localhost/";
}
}
}