From 50ab206892771670c1f0ff7b691045b6605b897c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 13 Jun 2019 15:04:21 +0200 Subject: [PATCH] Added more annotations, new To extension --- .../Extensions/EnumExtensions.cs | 2 ++ .../Extensions/System/BaseExtensions.cs | 13 +++++++++++++ .../Windows.UI/Composition/CompositionExtensions.cs | 1 + .../Windows.UI/Xaml/DependencyObjectExtensions.cs | 4 ++-- .../Windows.UI/Xaml/FrameworkElementExtensions.cs | 1 + .../Windows.UI/Xaml/UIElementExtensions.cs | 5 +++-- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/UICompositionAnimations/Extensions/EnumExtensions.cs b/UICompositionAnimations/Extensions/EnumExtensions.cs index 5af47e9..6856544 100644 --- a/UICompositionAnimations/Extensions/EnumExtensions.cs +++ b/UICompositionAnimations/Extensions/EnumExtensions.cs @@ -1,5 +1,6 @@ using System; using Windows.UI.Xaml.Media.Animation; +using JetBrains.Annotations; using UICompositionAnimations.Enums; namespace UICompositionAnimations.Extensions @@ -13,6 +14,7 @@ internal static class EnumExtensions /// Converts an easing value to the right easing function /// /// The desired easing function + [Pure, CanBeNull] public static EasingFunctionBase ToEasingFunction(this Easing ease) { switch (ease) diff --git a/UICompositionAnimations/Extensions/System/BaseExtensions.cs b/UICompositionAnimations/Extensions/System/BaseExtensions.cs index 96179ca..7e26dbe 100644 --- a/UICompositionAnimations/Extensions/System/BaseExtensions.cs +++ b/UICompositionAnimations/Extensions/System/BaseExtensions.cs @@ -11,10 +11,23 @@ public static class BaseExtensions /// /// Performs a direct cast on the given /// + /// The target type to return + /// The input to cast [MethodImpl(MethodImplOptions.AggressiveInlining)] [Pure] + [ContractAnnotation("null => null; notnull => notnull")] public static T To(this object o) => (T)o; + /// + /// Performs a safe cast to the specified type + /// + /// The target type to return, if possible + /// The input to try to convert + [MethodImpl(MethodImplOptions.AggressiveInlining)] + [Pure] + [ContractAnnotation("null => null; notnull => canbenull")] + public static TTo As([CanBeNull] this object o) where TTo : class => o as TTo; + /// /// Converts an angle in radians to degrees /// diff --git a/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs index 34d2f11..194b8f4 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Composition/CompositionExtensions.cs @@ -184,6 +184,7 @@ public static void BindSize([NotNull] this CompositionObject source, [NotNull] U /// The source instance /// The resulting , if existing [MustUseReturnValue] + [ContractAnnotation("=> true, dispatcher: notnull; => false, dispatcher: null")] public static bool TryGetDispatcher([NotNull] this CompositionObject source, out CoreDispatcher dispatcher) { try diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs index 4ef8761..dababa5 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/DependencyObjectExtensions.cs @@ -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; diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs index 2f4b865..99360b6 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/FrameworkElementExtensions.cs @@ -45,6 +45,7 @@ public static void SetVisualCenterPoint([NotNull] this FrameworkElement element, /// The optional explicit blur radius /// The optional to use to create an alpha mask for the /// The that hosts the + [NotNull] public static SpriteVisual AttachVisualShadow( [NotNull] this FrameworkElement element, [NotNull] UIElement target, bool apply, diff --git a/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs b/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs index 18c60e2..f8bc69b 100644 --- a/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs +++ b/UICompositionAnimations/Extensions/Windows.UI/Xaml/UIElementExtensions.cs @@ -20,6 +20,7 @@ public static class UIElementExtensions /// Returns the Visual object for a given UIElement /// /// The source UIElement + [Pure, NotNull] public static Visual GetVisual([NotNull] this UIElement element) => ElementCompositionPreview.GetElementVisual(element); #region Animations @@ -110,8 +111,8 @@ public static void BeginVector3Animation( /// The desired type /// The target to modify /// If , a new instance will always be created and assigned to the - /// - public static T GetTransform(this UIElement element, bool reset = true) where T : Transform, new() + [MustUseReturnValue, NotNull] + public static T GetTransform([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();