Skip to content

Commit

Permalink
Minor refactoring, added new Uri extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Mar 29, 2019
1 parent 8e63427 commit ec51c9b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
18 changes: 0 additions & 18 deletions UICompositionAnimations/Extensions/System/BaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,5 @@ public static class BaseExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
public static float ToRadians(this float degrees) => (float)(Math.PI / 180 * degrees);

/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="uri">The input <see cref="Uri"/> to process</param>
[Pure, NotNull]
internal static Uri ToAppxUri([NotNull] this Uri uri)
{
if (uri.Scheme.Equals("ms-resource"))
{
string path = uri.AbsolutePath.StartsWith("/Files")
? uri.AbsolutePath.Replace("/Files", string.Empty)
: uri.AbsolutePath;
return new Uri($"ms-appx://{path}");
}

return uri;
}
}
}
40 changes: 40 additions & 0 deletions UICompositionAnimations/Extensions/System/UriExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using JetBrains.Annotations;

namespace System
{
/// <summary>
/// An extension <see langword="class"/> for the <see cref="Uri"/> type
/// </summary>
public static class UriExtensions
{
/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="uri">The input <see cref="Uri"/> to process</param>
/// <remarks>This is needed because the XAML converter doesn't use the ms-appx:// prefix</remarks>
[Pure, NotNull]
internal static Uri ToAppxUri([NotNull] this Uri uri)
{
if (uri.Scheme.Equals("ms-resource"))
{
string path = uri.AbsolutePath.StartsWith("/Files")
? uri.AbsolutePath.Replace("/Files", string.Empty)
: uri.AbsolutePath;
return new Uri($"ms-appx://{path}");
}

return uri;
}

/// <summary>
/// Returns an <see cref="Uri"/> that starts with the ms-appx:// prefix
/// </summary>
/// <param name="path">The input relative path to convert</param>
[Pure, NotNull]
public static Uri ToAppxUri([NotNull] this string path)
{
string prefix = $"ms-appx://{(path.StartsWith('/') ? string.Empty : "/")}";
return new Uri($"{prefix}{path}");
}
}
}
1 change: 1 addition & 0 deletions UICompositionAnimations/UICompositionAnimations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
<Compile Include="Brushes\Effects\Interfaces\IPipelineEffect.cs" />
<Compile Include="Brushes\PipelineBrush.cs" />
<Compile Include="Brushes\Base\XamlCompositionEffectBrushBase.cs" />
<Compile Include="Extensions\System\UriExtensions.cs" />
<Compile Include="Helpers\Cache\HostBackdropInstanceWrapper.cs" />
<Compile Include="Helpers\Cache\ThreadSafeCompositionCache.cs" />
<Compile Include="Helpers\Cache\ThreadSafeCompositionMapCache.cs" />
Expand Down

0 comments on commit ec51c9b

Please sign in to comment.