Skip to content

Commit

Permalink
Added more annotations, new To<T> extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio0694 committed Jun 13, 2019
1 parent 5a43ab2 commit 50ab206
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions UICompositionAnimations/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Windows.UI.Xaml.Media.Animation;
using JetBrains.Annotations;
using UICompositionAnimations.Enums;

namespace UICompositionAnimations.Extensions
Expand All @@ -13,6 +14,7 @@ internal static class EnumExtensions
/// Converts an easing value to the right easing function
/// </summary>
/// <param name="ease">The desired easing function</param>
[Pure, CanBeNull]
public static EasingFunctionBase ToEasingFunction(this Easing ease)
{
switch (ease)
Expand Down
13 changes: 13 additions & 0 deletions UICompositionAnimations/Extensions/System/BaseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ public static class BaseExtensions
/// <summary>
/// Performs a direct cast on the given <see cref="object"/>
/// </summary>
/// <typeparam name="T">The target type to return</typeparam>
/// <param name="o">The input <see cref="object"/> to cast</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[ContractAnnotation("null => null; notnull => notnull")]
public static T To<T>(this object o) => (T)o;

/// <summary>
/// Performs a safe cast to the specified type
/// </summary>
/// <typeparam name="TTo">The target type to return, if possible</typeparam>
/// <param name="o">The input <see cref="object"/> to try to convert</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[Pure]
[ContractAnnotation("null => null; notnull => canbenull")]
public static TTo As<TTo>([CanBeNull] this object o) where TTo : class => o as TTo;

/// <summary>
/// Converts an angle in radians to degrees
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public static void BindSize([NotNull] this CompositionObject source, [NotNull] U
/// <param name="source">The source <see cref="CompositionObject"/> instance</param>
/// <param name="dispatcher">The resulting <see cref="CoreDispatcher"/>, if existing</param>
[MustUseReturnValue]
[ContractAnnotation("=> true, dispatcher: notnull; => false, dispatcher: null")]
public static bool TryGetDispatcher([NotNull] this CompositionObject source, out CoreDispatcher dispatcher)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static DoubleAnimation CreateDoubleAnimation(
From = from,
To = to,
Duration = duration,
EnableDependentAnimation = enableDependecyAnimations
EnableDependentAnimation = enableDependecyAnimations,
EasingFunction = easing.ToEasingFunction()
};
if (easing != Easing.Linear) animation.EasingFunction = easing.ToEasingFunction();
Storyboard.SetTarget(animation, target);
Storyboard.SetTargetProperty(animation, property);
return animation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void SetVisualCenterPoint([NotNull] this FrameworkElement element,
/// <param name="blurRadius">The optional explicit <see cref="DropShadow"/> blur radius</param>
/// <param name="maskElement">The optional <see cref="UIElement"/> to use to create an alpha mask for the <see cref="DropShadow"/></param>
/// <returns>The <see cref="SpriteVisual"/> that hosts the <see cref="DropShadow"/></returns>
[NotNull]
public static SpriteVisual AttachVisualShadow(
[NotNull] this FrameworkElement element, [NotNull] UIElement target,
bool apply,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public static class UIElementExtensions
/// Returns the Visual object for a given UIElement
/// </summary>
/// <param name="element">The source UIElement</param>
[Pure, NotNull]
public static Visual GetVisual([NotNull] this UIElement element) => ElementCompositionPreview.GetElementVisual(element);

#region Animations
Expand Down Expand Up @@ -110,8 +111,8 @@ public static void BeginVector3Animation(
/// <typeparam name="T">The desired <see cref="Transform"/> type</typeparam>
/// <param name="element">The target <see cref="UIElement"/> to modify</param>
/// <param name="reset">If <see langword="true"/>, a new <see cref="Transform"/> instance will always be created and assigned to the <see cref="UIElement"/></param>
/// <returns></returns>
public static T GetTransform<T>(this UIElement element, bool reset = true) where T : Transform, new()
[MustUseReturnValue, NotNull]
public static T GetTransform<T>([NotNull] this UIElement element, bool reset = true) where T : Transform, new()
{
// Return the existing transform object, if it exists
if (element.RenderTransform is T && !reset) return element.RenderTransform.To<T>();
Expand Down

0 comments on commit 50ab206

Please sign in to comment.