mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-01-11 19:44:55 +00:00
feat: Added GetParentUri method to UriExtensions
This commit is contained in:
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Added GetParentUri method to UriExtensions
|
||||||
|
|
||||||
## [14.0.0] - 2021-01-14
|
## [14.0.0] - 2021-01-14
|
||||||
### Added
|
### Added
|
||||||
- Added Get and Set extensions to PropertyInfo in SIMPLSHARP to mimic overloads avaliable in NETSTANDARD
|
- Added Get and Set extensions to PropertyInfo in SIMPLSHARP to mimic overloads avaliable in NETSTANDARD
|
||||||
|
|||||||
@@ -18,5 +18,13 @@ namespace ICD.Common.Utils.Tests.Extensions
|
|||||||
{
|
{
|
||||||
Assert.AreEqual(expected, new Uri(uriString).GetPassword());
|
Assert.AreEqual(expected, new Uri(uriString).GetPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[TestCase("http://www.test.com/a/b/c", "http://www.test.com/a/b/")]
|
||||||
|
[TestCase("http://www.test.com/a/b/", "http://www.test.com/a/")]
|
||||||
|
[TestCase("http://www.test.com/", "http://www.test.com/")]
|
||||||
|
public void GetParentUri(string uriString, string expected)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(expected, new Uri(uriString).GetParentUri().ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,5 +62,23 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
|
|
||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns a new Uri representing the Uri for the parent path.
|
||||||
|
/// E.g.
|
||||||
|
/// www.test.com/A/B/C
|
||||||
|
/// Becomes
|
||||||
|
/// www.test.com/A/B/
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="extends"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Uri GetParentUri([NotNull] this Uri extends)
|
||||||
|
{
|
||||||
|
if (extends == null)
|
||||||
|
throw new ArgumentNullException("extends");
|
||||||
|
|
||||||
|
string parentUriString = extends.AbsoluteUri.Remove(extends.AbsoluteUri.Length - extends.Segments.Last().Length);
|
||||||
|
return new Uri(parentUriString, UriKind.Absolute);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user