Skip to content

Use Global Usings and aliases to reduce #ifdef usage #285

@michael-hawker

Description

@michael-hawker

I noticed a number of ifdefs just for doc comments like so:

#if WinUI
    /// <summary>
    /// An action that will change the state of the specified <seealso cref="Microsoft.UI.Xaml.Media.Animation.Storyboard"/> when executed.
    /// </summary>
#else
    /// <summary>
    /// An action that will change the state of the specified <seealso cref="Windows.UI.Xaml.Media.Animation.Storyboard"/> when executed.
    /// </summary>
#endif

As well as many at the top of files:

#if WinUI
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Media.Animation;
#else
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media.Animation;
#endif

By using global usings and aliasing, we can reduce this duplication within the project. References:

By moving the general Microsoft/Windows usings to the csproj as globals, this can remove the namespaces at the top of each file making it cleaner to maintain and get to the functional code.

By using aliases, if not in the csproj at the top, it can make it easier to maintain comments for classes. See after here:

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

// This could also be moved to alias in csproj if desired... as we don't have too many unique types for these or they are commonly used otherwise.
#if WinUI
using Storyboard = Microsoft.UI.Xaml.Media.Animation.Storyboard;
#else
using Storyboard = Windows.UI.Xaml.Media.Animation.Storyboard;
#endif

namespace Microsoft.Xaml.Interactivity
{
    /// <summary>
    /// An action that will change the state of the specified <seealso cref="Storyboard"/> when executed.
    /// </summary>
    public sealed class ControlStoryboardAction : DependencyObject, IAction
    {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions