Skip to content

Commit

Permalink
feat: Address Rule CA2211
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering authored and jeromelaban committed Apr 25, 2023
1 parent 3688e7b commit 57d281f
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 37 deletions.
17 changes: 17 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9166,6 +9166,23 @@
<Member fullName="System.Runtime.InteropServices.NFloat Uno.UI.ViewHelper::MainScreenScale" reason="Api alignments" />
<Member fullName="System.Boolean Uno.UI.ViewHelper::IsRetinaDisplay" reason="Api alignments" />
<Member fullName="System.nfloat Uno.UI.ViewHelper::MainScreenScale" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Microsoft.UI.Xaml.Controls.StackLayout::SpacingProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Microsoft.UI.Xaml.Controls.StackLayout::DisableVirtualizationProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Windows.UI.Xaml.Documents.TextElement::BaseLineAlignmentProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::IsEnabledProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::ContentProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::RightPaneProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::RightPaneOpenLengthProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::IsRightPaneOpenProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::RightPaneBackgroundProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::LeftPaneProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::LeftPaneOpenLengthProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::IsLeftPaneOpenProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.BindableDrawerLayout::LeftPaneBackgroundProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.Legacy.GridView::PaddingProperty" reason="Api alignments" />
<Member fullName="Windows.UI.Xaml.DependencyProperty Uno.UI.Controls.Legacy.GridView::ItemContainerStyleProperty" reason="Api alignments" />
<Member fullName="Foundation.NSString Windows.Media.Playback.MediaPlayer::RateObservationContext" reason="Api alignments" />
<Member fullName="UIKit.UIInterfaceOrientationMask[] Windows.Graphics.Display.DisplayInformation::PreferredOrientations" reason="Api alignments" />
</Fields>
<Properties>
<Member fullName="Microsoft.UI.Windowing.AppWindowConfiguration Microsoft.UI.Windowing.AppWindow::Configuration()" reason="Not present in WinAppSDK 1.2" />
Expand Down
1 change: 0 additions & 1 deletion build/nVentive-generic.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2211" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Error" />
<Rule Id="CA2214" Action="Error" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ private static bool InnerInvokeJSUnmarshalled(string functionIdentifier, IntPtr
return res != IntPtr.Zero;
}

#pragma warning disable CA2211
/// <summary>
/// Provides an override for javascript invokes.
/// </summary>
public static Func<string, string>? InvokeJSOverride;
#pragma warning restore CA2211

public static string InvokeJS(string str)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Uno.UI/Controls/BindableDrawerLayout.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public bool IsEnabled
set { this.SetValue(IsEnabledProperty, value); }
}

public static DependencyProperty IsEnabledProperty =
public static DependencyProperty IsEnabledProperty { get; } =
DependencyProperty.Register(
"IsEnabled",
typeof(bool),
Expand Down Expand Up @@ -189,7 +189,7 @@ public UIElement Content
set { this.SetValue(ContentProperty, value); }
}

public static DependencyProperty ContentProperty =
public static DependencyProperty ContentProperty { get; } =
DependencyProperty.Register(
"Content",
typeof(UIElement),
Expand Down Expand Up @@ -227,7 +227,7 @@ public UIElement RightPane
set { this.SetValue(RightPaneProperty, value); }
}

public static DependencyProperty RightPaneProperty =
public static DependencyProperty RightPaneProperty { get; } =
DependencyProperty.Register(
"RightPane",
typeof(UIElement),
Expand Down Expand Up @@ -263,7 +263,7 @@ public double RightPaneOpenLength
set { this.SetValue(RightPaneOpenLengthProperty, value); }
}

public static DependencyProperty RightPaneOpenLengthProperty =
public static DependencyProperty RightPaneOpenLengthProperty { get; } =
DependencyProperty.Register(
"RightPaneOpenLength",
typeof(double),
Expand All @@ -289,7 +289,7 @@ public bool IsRightPaneOpen
set { this.SetValue(IsRightPaneOpenProperty, value); }
}

public static DependencyProperty IsRightPaneOpenProperty =
public static DependencyProperty IsRightPaneOpenProperty { get; } =
DependencyProperty.Register(
"IsRightPaneOpen",
typeof(bool),
Expand Down Expand Up @@ -322,7 +322,7 @@ public Brush RightPaneBackground
set { this.SetValue(RightPaneBackgroundProperty, value); }
}

public static DependencyProperty RightPaneBackgroundProperty =
public static DependencyProperty RightPaneBackgroundProperty { get; } =
DependencyProperty.Register(
"RightPaneBackground",
typeof(Brush),
Expand Down Expand Up @@ -351,7 +351,7 @@ public UIElement LeftPane
set { this.SetValue(LeftPaneProperty, value); }
}

public static DependencyProperty LeftPaneProperty =
public static DependencyProperty LeftPaneProperty { get; } =
DependencyProperty.Register(
"LeftPane",
typeof(UIElement),
Expand Down Expand Up @@ -387,7 +387,7 @@ public double LeftPaneOpenLength
set { this.SetValue(LeftPaneOpenLengthProperty, value); }
}

public static DependencyProperty LeftPaneOpenLengthProperty =
public static DependencyProperty LeftPaneOpenLengthProperty { get; } =
DependencyProperty.Register(
"LeftPaneOpenLength",
typeof(double),
Expand All @@ -413,7 +413,7 @@ public bool IsLeftPaneOpen
set { this.SetValue(IsLeftPaneOpenProperty, value); }
}

public static DependencyProperty IsLeftPaneOpenProperty =
public static DependencyProperty IsLeftPaneOpenProperty { get; } =
DependencyProperty.Register(
"IsLeftPaneOpen",
typeof(bool),
Expand Down Expand Up @@ -446,7 +446,7 @@ public Brush LeftPaneBackground
set { this.SetValue(LeftPaneBackgroundProperty, value); }
}

public static DependencyProperty LeftPaneBackgroundProperty =
public static DependencyProperty LeftPaneBackgroundProperty { get; } =
DependencyProperty.Register(
"LeftPaneBackground",
typeof(Brush),
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.UI/FeatureConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public static class ListViewBase
/// performance at the expense of consuming more memory and taking longer to initially load. Setting this to null will leave
/// the default value at the UWP default of 4.0.
/// </summary>
public static double? DefaultCacheLength = 1.0;
public static double? DefaultCacheLength { get; set; } = 1.0;

#if __IOS__ || __ANDROID__
/// <summary>
Expand All @@ -362,7 +362,7 @@ public static class NativeListViewBase
/// Sets this value to remove item animation for <see cref="UnoRecyclerView"/>. This prevents <see cref="UnoRecyclerView"/>
/// from crashing when pressured: Tmp detached view should be removed from RecyclerView before it can be recycled
/// </summary>
public static bool RemoveItemAnimator = true;
public static bool RemoveItemAnimator { get; set; } = true;

/// <summary>
/// Indicates if a full recycling pass should be achieved on drop (re-order) on a ListView instead of a simple layout pass.
Expand All @@ -371,12 +371,12 @@ public static class NativeListViewBase
/// This flag should be kept to 'false' if you turned <see cref="RemoveItemAnimator"/> to 'false'.
/// Forcing a recycling pass with ItemAnimator is known to cause a flicker of the whole list.
/// </remarks>
public static bool ForceRecycleOnDrop;
public static bool ForceRecycleOnDrop { get; set; }

/// <summary>
/// Sets a value indicating whether the item snapping will be implemented by the native <see cref="AndroidX.RecyclerView.Widget.SnapHelper"/> or by Uno.
/// </summary>
public static bool UseNativeSnapHelper = true;
public static bool UseNativeSnapHelper { get; set; } = true;
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Orientation Orientation
#endregion

#region Spacing - DP with common callback
public static DependencyProperty SpacingProperty = DependencyProperty.Register(
public static DependencyProperty SpacingProperty { get; } = DependencyProperty.Register(
"Spacing", typeof(double), typeof(StackLayout), new FrameworkPropertyMetadata(default(double), OnDependencyPropertyChanged));

public double Spacing
Expand All @@ -33,7 +33,7 @@ public double Spacing
#endregion

#region DisableVirtualization
public static DependencyProperty DisableVirtualizationProperty = DependencyProperty.Register(
public static DependencyProperty DisableVirtualizationProperty { get; } = DependencyProperty.Register(
"DisableVirtualization ", typeof(bool), typeof(StackLayout), new FrameworkPropertyMetadata(default(bool), OnDependencyPropertyChanged));

public bool DisableVirtualization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Thickness Padding
set { SetValue(PaddingProperty, value); }
}

public static DependencyProperty PaddingProperty =
public static DependencyProperty PaddingProperty { get; } =
DependencyProperty.Register(
"Padding",
typeof(Thickness),
Expand Down Expand Up @@ -172,7 +172,7 @@ public Style ItemContainerStyle
set { SetValue(ItemContainerStyleProperty, value); }
}

public static DependencyProperty ItemContainerStyleProperty =
public static DependencyProperty ItemContainerStyleProperty { get; } =
DependencyProperty.Register(
"ItemContainerStyle",
typeof(Style),
Expand Down Expand Up @@ -292,7 +292,7 @@ private void HandleItemSelection(ItemClickEventArgs args)
case ListViewSelectionMode.Single:
var selectedItem = BindableAdapter.SelectedItems.FirstOrDefault();

// Unselect the current item only if a new selection is made or
// Unselect the current item only if a new selection is made or
// the option to unselect the current item is activated.
if (selectedItem != null && (selectedItem != newSelection || UnselectOnClick))
{
Expand Down Expand Up @@ -337,7 +337,7 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
if (heightMode == MeasureSpecMode.Unspecified)
{
// By default, given an Unspecified available height, the GridView will be measured to take the height of a single row.
// Therefore, we need the code below to ensure the GridView takes the height of all its items.
// Therefore, we need the code below to ensure the GridView takes the height of all its items.
heightMeasureSpec = ViewHelper.MakeMeasureSpec(int.MaxValue, MeasureSpecMode.AtMost);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Documents/TextElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public BaseLineAlignment BaseLineAlignment
set => SetValue(BaseLineAlignmentProperty, value);
}

public static DependencyProperty BaseLineAlignmentProperty =
public static DependencyProperty BaseLineAlignmentProperty { get; } =
DependencyProperty.Register(
"BaseLineAlignment",
typeof(BaseLineAlignment),
Expand Down Expand Up @@ -315,7 +315,7 @@ public bool AllowFocusOnInteraction
public string Name { get; set; }
#endif

/// <summary>
/// <summary>
/// Retrieves the parent RichTextBox/CRichTextBlock/TextBlock.
/// </summary>
/// <returns>FrameworkElement or <see langword="null"/>.</returns>
Expand Down
2 changes: 2 additions & 0 deletions src/Uno.UI/UI/Xaml/Media/ImageSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public static class TraceProvider

const string MsAppXScheme = "ms-appx";

#pragma warning disable CA2211
/// <summary>
/// The default downloader instance used by all the new instances of <see cref="ImageSource"/>.
/// </summary>
Expand All @@ -45,6 +46,7 @@ public static class TraceProvider
/// The image downloader for the current instance.
/// </summary>
public IImageSourceDownloader Downloader;
#pragma warning restore CA2211

#if __ANDROID__ || __IOS__ || __MACOS__
/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Uno.UI/UI/Xaml/UIElement.ThemeShadow.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ namespace Windows.UI.Xaml;

public partial class UIElement
{
public static float ShadowOffsetMax = 150;
public static float ShadowAlphaFallback = 0.5f;
public static float ShadowAlphaMultiplier = 0.18f;
public static float ShadowOffsetAlphaModifier = 1f / 650f;
public static float ShadowSigmaXModifier = 1f / 5f;
public static float ShadowSigmaYModifier = 1f / 3.5f;
private const float ShadowOffsetMax = 150;
private const float ShadowAlphaFallback = 0.5f;
private const float ShadowAlphaMultiplier = 0.18f;
private const float ShadowOffsetAlphaModifier = 1f / 650f;
private const float ShadowSigmaXModifier = 1f / 5f;
private const float ShadowSigmaYModifier = 1f / 3.5f;

partial void UnsetShadow()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UWP/Devices/Sensors/SimpleOrientationSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public partial class SimpleOrientationSensor
{
#region Static

public static SimpleOrientationSensor _instance;
private static SimpleOrientationSensor _instance;

public static SimpleOrientationSensor GetDefault()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.UWP/Graphics/Display/DisplayInformation.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed partial class DisplayInformation

private NSObject _didChangeStatusBarOrientationObserver;

public static UIInterfaceOrientationMask[] PreferredOrientations =
private static readonly UIInterfaceOrientationMask[] _preferredOrientations =
{
UIInterfaceOrientationMask.Portrait,
UIInterfaceOrientationMask.LandscapeRight,
Expand All @@ -27,7 +27,7 @@ public sealed partial class DisplayInformation
public DisplayOrientations CurrentOrientation => GetCurrentOrientation();

/// <summary>
//// Gets the native orientation of the display monitor,
//// Gets the native orientation of the display monitor,
/// which is typically the orientation where the buttons
/// on the device match the orientation of the monitor.
/// </summary>
Expand Down Expand Up @@ -68,7 +68,7 @@ public ResolutionScale ResolutionScale
}

/// <summary>
/// Sets the NativeOrientation property
/// Sets the NativeOrientation property
/// to appropriate value based on user interface idiom
/// </summary>
private DisplayOrientations GetNativeOrientation()
Expand Down Expand Up @@ -182,7 +182,7 @@ static partial void SetOrientationPartial(DisplayOrientations orientations)
{
//Rotate to the most preferred orientation that is requested
//e.g. if our mask is Portrait | PortraitUpsideDown, we prefer to initially rotate to Portrait rather than PortraitUpsideDown
var toOrientation = PreferredOrientations.FirstOrDefault(ori => toOrientationMask.HasFlag(ori)).ToUIInterfaceOrientation();
var toOrientation = _preferredOrientations.FirstOrDefault(ori => toOrientationMask.HasFlag(ori)).ToUIInterfaceOrientation();

UIDevice.CurrentDevice
.SetValueForKey(
Expand Down
6 changes: 3 additions & 3 deletions src/Uno.UWP/Media/Playback/MediaPlayer.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private void OnMediaEndedCore(object sender, NSNotificationEventArgs args)
private NSObject _playbackStalledNotification;
private NSObject _didPlayToEndTimeNotification;

public static NSString RateObservationContext = new NSString("AVCustomEditPlayerViewControllerRateObservationContext");
private static readonly NSString _rateObservationContext = new NSString("AVCustomEditPlayerViewControllerRateObservationContext");

const string MsAppXScheme = "ms-appx";

Expand All @@ -142,7 +142,7 @@ private void TryDisposePlayer()
_player.CurrentItem?.RemoveObserver(_observer, new NSString("loadedTimeRanges"), _player.Handle);
_player.CurrentItem?.RemoveObserver(_observer, new NSString("status"), _player.Handle);
_player.CurrentItem?.RemoveObserver(_observer, new NSString("duration"), _player.Handle);
_player.RemoveObserver(_observer, new NSString("rate"), RateObservationContext.Handle);
_player.RemoveObserver(_observer, new NSString("rate"), _rateObservationContext.Handle);
_player.RemoveTimeObserver(_periodicTimeObserverObject);
_player.RemoveAllItems();
}
Expand Down Expand Up @@ -180,7 +180,7 @@ private void InitializePlayer()
}
#endif
_videoLayer.AddObserver(_observer, new NSString("videoRect"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Initial, _videoLayer.Handle);
_player.AddObserver(_observer, new NSString("rate"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Initial, RateObservationContext.Handle);
_player.AddObserver(_observer, new NSString("rate"), NSKeyValueObservingOptions.New | NSKeyValueObservingOptions.Initial, _rateObservationContext.Handle);

_itemFailedToPlayToEndTimeNotification = AVPlayerItem.Notifications.ObserveItemFailedToPlayToEndTime(_observer.OnMediaFailed);
_playbackStalledNotification = AVPlayerItem.Notifications.ObservePlaybackStalled(_observer.OnMediaStalled);
Expand Down

0 comments on commit 57d281f

Please sign in to comment.