diff --git a/src/Controls/src/Core/.editorconfig b/src/Controls/src/Core/.editorconfig new file mode 100644 index 000000000000..6cfd0e70880d --- /dev/null +++ b/src/Controls/src/Core/.editorconfig @@ -0,0 +1,2 @@ +[*.cs] +dotnet_diagnostic.CA1507.severity = error diff --git a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs index 5e9dc3d6bc43..3d63d122c3a6 100644 --- a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs +++ b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls public partial class ActivityIndicator : View, IColorElement, IElementConfiguration, IActivityIndicator { /// Bindable property for . - public static readonly BindableProperty IsRunningProperty = BindableProperty.Create("IsRunning", typeof(bool), typeof(ActivityIndicator), default(bool)); + public static readonly BindableProperty IsRunningProperty = BindableProperty.Create(nameof(IsRunning), typeof(bool), typeof(ActivityIndicator), default(bool)); /// Bindable property for . public static readonly BindableProperty ColorProperty = ColorElement.ColorProperty; diff --git a/src/Controls/src/Core/Animation.cs b/src/Controls/src/Core/Animation.cs index 2cc3621c0ec9..8a2c60c726ba 100644 --- a/src/Controls/src/Core/Animation.cs +++ b/src/Controls/src/Core/Animation.cs @@ -45,10 +45,10 @@ public Animation(Action callback, double start = 0.0f, double end = 1.0f public void Add(double beginAt, double finishAt, Animation animation) { if (beginAt < 0 || beginAt > 1) - throw new ArgumentOutOfRangeException("beginAt"); + throw new ArgumentOutOfRangeException(nameof(beginAt)); if (finishAt < 0 || finishAt > 1) - throw new ArgumentOutOfRangeException("finishAt"); + throw new ArgumentOutOfRangeException(nameof(finishAt)); if (finishAt <= beginAt) throw new ArgumentException("finishAt must be greater than beginAt"); diff --git a/src/Controls/src/Core/Cells/Cell.cs b/src/Controls/src/Core/Cells/Cell.cs index c63c4a94d386..d04db7438c86 100644 --- a/src/Controls/src/Core/Cells/Cell.cs +++ b/src/Controls/src/Core/Cells/Cell.cs @@ -16,7 +16,7 @@ public abstract class Cell : Element, ICellController, IFlowDirectionController, /// public const int DefaultCellHeight = 40; /// Bindable property for . - public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), typeof(Cell), true, propertyChanged: OnIsEnabledPropertyChanged); + public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Cell), true, propertyChanged: OnIsEnabledPropertyChanged); ObservableCollection _contextActions; List _currentContextActions; @@ -116,11 +116,11 @@ public double Height if (_height == value) return; - OnPropertyChanging("Height"); - OnPropertyChanging("RenderHeight"); + OnPropertyChanging(nameof(Height)); + OnPropertyChanging(nameof(RenderHeight)); _height = value; - OnPropertyChanged("Height"); - OnPropertyChanged("RenderHeight"); + OnPropertyChanged(nameof(Height)); + OnPropertyChanged(nameof(RenderHeight)); } } @@ -265,7 +265,7 @@ void OnContextActionsChanged(object sender, NotifyCollectionChangedEventArgs e) _currentContextActions = new List(_contextActions); - OnPropertyChanged("HasContextActions"); + OnPropertyChanged(nameof(HasContextActions)); } async void OnForceUpdateSizeRequested() @@ -279,7 +279,7 @@ async void OnForceUpdateSizeRequested() static void OnIsEnabledPropertyChanged(BindableObject bindable, object oldvalue, object newvalue) { - (bindable as Cell).OnPropertyChanged("HasContextActions"); + (bindable as Cell).OnPropertyChanged(nameof(HasContextActions)); } void OnParentPropertyChanged(object sender, PropertyChangedEventArgs e) @@ -287,7 +287,7 @@ void OnParentPropertyChanged(object sender, PropertyChangedEventArgs e) // Technically we might be raising this even if it didn't change, but I'm taking the bet that // its uncommon enough that we don't want to take the penalty of N GetValue calls to verify. if (e.PropertyName == "RowHeight") - OnPropertyChanged("RenderHeight"); + OnPropertyChanged(nameof(RenderHeight)); else if (e.PropertyName == VisualElement.FlowDirectionProperty.PropertyName || e.PropertyName == VisualElement.VisualProperty.PropertyName) PropertyPropagationController.PropagatePropertyChanged(e.PropertyName); @@ -296,7 +296,7 @@ void OnParentPropertyChanged(object sender, PropertyChangedEventArgs e) void OnParentPropertyChanging(object sender, PropertyChangingEventArgs e) { if (e.PropertyName == "RowHeight") - OnPropertyChanging("RenderHeight"); + OnPropertyChanging(nameof(RenderHeight)); } #if ANDROID diff --git a/src/Controls/src/Core/Cells/EntryCell.cs b/src/Controls/src/Core/Cells/EntryCell.cs index b84fbd52484e..4ec072392262 100644 --- a/src/Controls/src/Core/Cells/EntryCell.cs +++ b/src/Controls/src/Core/Cells/EntryCell.cs @@ -9,19 +9,19 @@ namespace Microsoft.Maui.Controls public class EntryCell : Cell, ITextAlignmentElement, IEntryCellController, ITextAlignment { /// Bindable property for . - public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(EntryCell), null, BindingMode.TwoWay); + public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(EntryCell), null, BindingMode.TwoWay); /// Bindable property for . - public static readonly BindableProperty LabelProperty = BindableProperty.Create("Label", typeof(string), typeof(EntryCell), null); + public static readonly BindableProperty LabelProperty = BindableProperty.Create(nameof(Label), typeof(string), typeof(EntryCell), null); /// Bindable property for . - public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create("Placeholder", typeof(string), typeof(EntryCell), null); + public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(nameof(Placeholder), typeof(string), typeof(EntryCell), null); /// Bindable property for . - public static readonly BindableProperty LabelColorProperty = BindableProperty.Create("LabelColor", typeof(Color), typeof(EntryCell), null); + public static readonly BindableProperty LabelColorProperty = BindableProperty.Create(nameof(LabelColor), typeof(Color), typeof(EntryCell), null); /// Bindable property for . - public static readonly BindableProperty KeyboardProperty = BindableProperty.Create("Keyboard", typeof(Keyboard), typeof(EntryCell), Keyboard.Default); + public static readonly BindableProperty KeyboardProperty = BindableProperty.Create(nameof(Keyboard), typeof(Keyboard), typeof(EntryCell), Keyboard.Default); /// Bindable property for . public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; diff --git a/src/Controls/src/Core/Cells/ImageCell.cs b/src/Controls/src/Core/Cells/ImageCell.cs index bc7ac693c985..475df8cf322f 100644 --- a/src/Controls/src/Core/Cells/ImageCell.cs +++ b/src/Controls/src/Core/Cells/ImageCell.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Controls public class ImageCell : TextCell { /// Bindable property for . - public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create("ImageSource", typeof(ImageSource), typeof(ImageCell), null, + public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(ImageCell), null, propertyChanging: (bindable, oldvalue, newvalue) => ((ImageCell)bindable).OnSourcePropertyChanging((ImageSource)oldvalue, (ImageSource)newvalue), propertyChanged: (bindable, oldvalue, newvalue) => ((ImageCell)bindable).OnSourcePropertyChanged((ImageSource)oldvalue, (ImageSource)newvalue)); diff --git a/src/Controls/src/Core/Cells/SwitchCell.cs b/src/Controls/src/Core/Cells/SwitchCell.cs index 73bae2b866cf..3703c1f32013 100644 --- a/src/Controls/src/Core/Cells/SwitchCell.cs +++ b/src/Controls/src/Core/Cells/SwitchCell.cs @@ -8,14 +8,14 @@ namespace Microsoft.Maui.Controls public class SwitchCell : Cell { /// Bindable property for . - public static readonly BindableProperty OnProperty = BindableProperty.Create("On", typeof(bool), typeof(SwitchCell), false, propertyChanged: (obj, oldValue, newValue) => + public static readonly BindableProperty OnProperty = BindableProperty.Create(nameof(On), typeof(bool), typeof(SwitchCell), false, propertyChanged: (obj, oldValue, newValue) => { var switchCell = (SwitchCell)obj; switchCell.OnChanged?.Invoke(obj, new ToggledEventArgs((bool)newValue)); }, defaultBindingMode: BindingMode.TwoWay); /// Bindable property for . - public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(SwitchCell), default(string)); + public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(SwitchCell), default(string)); /// Bindable property for . public static readonly BindableProperty OnColorProperty = BindableProperty.Create(nameof(OnColor), typeof(Color), typeof(SwitchCell), null); diff --git a/src/Controls/src/Core/Cells/TextCell.cs b/src/Controls/src/Core/Cells/TextCell.cs index d9b85e2e80c0..544f6ba58615 100644 --- a/src/Controls/src/Core/Cells/TextCell.cs +++ b/src/Controls/src/Core/Cells/TextCell.cs @@ -9,7 +9,7 @@ namespace Microsoft.Maui.Controls public class TextCell : Cell { /// Bindable property for . - public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(TextCell), default(ICommand), + public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(TextCell), default(ICommand), propertyChanging: (bindable, oldvalue, newvalue) => { var textCell = (TextCell)bindable; @@ -28,7 +28,7 @@ public class TextCell : Cell }); /// Bindable property for . - public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(TextCell), default(object), + public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(TextCell), default(object), propertyChanged: (bindable, oldvalue, newvalue) => { var textCell = (TextCell)bindable; @@ -39,16 +39,16 @@ public class TextCell : Cell }); /// Bindable property for . - public static readonly BindableProperty TextProperty = BindableProperty.Create("Text", typeof(string), typeof(TextCell), default(string)); + public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(TextCell), default(string)); /// Bindable property for . - public static readonly BindableProperty DetailProperty = BindableProperty.Create("Detail", typeof(string), typeof(TextCell), default(string)); + public static readonly BindableProperty DetailProperty = BindableProperty.Create(nameof(Detail), typeof(string), typeof(TextCell), default(string)); /// Bindable property for . - public static readonly BindableProperty TextColorProperty = BindableProperty.Create("TextColor", typeof(Color), typeof(TextCell), null); + public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TextCell), null); /// Bindable property for . - public static readonly BindableProperty DetailColorProperty = BindableProperty.Create("DetailColor", typeof(Color), typeof(TextCell), null); + public static readonly BindableProperty DetailColorProperty = BindableProperty.Create(nameof(DetailColor), typeof(Color), typeof(TextCell), null); /// public ICommand Command diff --git a/src/Controls/src/Core/Compatibility/Android/FontNamedSizeService.cs b/src/Controls/src/Core/Compatibility/Android/FontNamedSizeService.cs index d4bcb9bc7261..8597c5a6be22 100644 --- a/src/Controls/src/Core/Compatibility/Android/FontNamedSizeService.cs +++ b/src/Controls/src/Core/Compatibility/Android/FontNamedSizeService.cs @@ -69,7 +69,7 @@ public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSi case NamedSize.Title: return 24; default: - throw new ArgumentOutOfRangeException("size"); + throw new ArgumentOutOfRangeException(nameof(size)); } } switch (size) @@ -101,7 +101,7 @@ public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSi case NamedSize.Title: return 24; default: - throw new ArgumentOutOfRangeException("size"); + throw new ArgumentOutOfRangeException(nameof(size)); } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellAdapter.cs index 02e9f7b5c5b8..3735dc9a8f6f 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/CellAdapter.cs @@ -32,7 +32,7 @@ public abstract class CellAdapter : BaseAdapter, AdapterView.IOnItemLong protected CellAdapter(Context context) { if (context == null) - throw new ArgumentNullException("context"); + throw new ArgumentNullException(nameof(context)); _context = context; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index 84ba561a93f8..4d44d032c580 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -599,9 +599,9 @@ void UpdateTranslucent() void InsertPageBefore(Page page, Page before) { if (before.Handler is not IPlatformViewHandler nvh) - throw new ArgumentNullException("before"); + throw new ArgumentNullException(nameof(before)); if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); var pageContainer = CreateViewControllerForPage(page); var target = nvh.ViewController.ParentViewController; @@ -641,7 +641,7 @@ void OnRemovedPageRequested(object sender, NavigationRequestedEventArgs e) void RemovePage(Page page) { if (page?.Handler is not IPlatformViewHandler nvh) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); if (page == Current) throw new NotSupportedException(); // should never happen as NavPage protects against this diff --git a/src/Controls/src/Core/Compatibility/iOS/Extensions/CellExtensions.cs b/src/Controls/src/Core/Compatibility/iOS/Extensions/CellExtensions.cs index d1f499c75967..490391ad2dd0 100644 --- a/src/Controls/src/Core/Compatibility/iOS/Extensions/CellExtensions.cs +++ b/src/Controls/src/Core/Compatibility/iOS/Extensions/CellExtensions.cs @@ -10,7 +10,7 @@ internal static class CellExtensions internal static NSIndexPath GetIndexPath(this Cell self) { if (self == null) - throw new ArgumentNullException("self"); + throw new ArgumentNullException(nameof(self)); NSIndexPath path; diff --git a/src/Controls/src/Core/Compatibility/iOS/FontNamedSizeService.cs b/src/Controls/src/Core/Compatibility/iOS/FontNamedSizeService.cs index ea77d5afbce9..accf4c5101b9 100644 --- a/src/Controls/src/Core/Compatibility/iOS/FontNamedSizeService.cs +++ b/src/Controls/src/Core/Compatibility/iOS/FontNamedSizeService.cs @@ -72,7 +72,7 @@ public double GetNamedSize(NamedSize size, Type targetElementType, bool useOldSi #endif default: - throw new ArgumentOutOfRangeException("size"); + throw new ArgumentOutOfRangeException(nameof(size)); } } } diff --git a/src/Controls/src/Core/ElementTemplate.cs b/src/Controls/src/Core/ElementTemplate.cs index d35f160f5049..2b1bebe692d1 100644 --- a/src/Controls/src/Core/ElementTemplate.cs +++ b/src/Controls/src/Core/ElementTemplate.cs @@ -25,7 +25,7 @@ internal ElementTemplate( : this() { if (type == null) - throw new ArgumentNullException("type"); + throw new ArgumentNullException(nameof(type)); _canRecycle = true; _type = type; @@ -33,7 +33,7 @@ internal ElementTemplate( LoadTemplate = () => Activator.CreateInstance(type); } - internal ElementTemplate(Func loadTemplate) : this() => LoadTemplate = loadTemplate ?? throw new ArgumentNullException("loadTemplate"); + internal ElementTemplate(Func loadTemplate) : this() => LoadTemplate = loadTemplate ?? throw new ArgumentNullException(nameof(loadTemplate)); public Func LoadTemplate { get; set; } diff --git a/src/Controls/src/Core/FileImageSource.cs b/src/Controls/src/Core/FileImageSource.cs index 5172ae910d28..d6bb3fd4cde9 100644 --- a/src/Controls/src/Core/FileImageSource.cs +++ b/src/Controls/src/Core/FileImageSource.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls public sealed partial class FileImageSource : ImageSource { /// Bindable property for . - public static readonly BindableProperty FileProperty = BindableProperty.Create("File", typeof(string), typeof(FileImageSource), default(string)); + public static readonly BindableProperty FileProperty = BindableProperty.Create(nameof(File), typeof(string), typeof(FileImageSource), default(string)); /// public override bool IsEmpty => string.IsNullOrEmpty(File); diff --git a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs index 68d77e558447..333839a858b8 100644 --- a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs @@ -41,7 +41,7 @@ public Page Detail set { if (_detail != null && value == null) - throw new ArgumentNullException("value", "Detail cannot be set to null once a value is set."); + throw new ArgumentNullException(nameof(value), "Detail cannot be set to null once a value is set."); if (_detail == value) return; @@ -92,7 +92,7 @@ public Page Flyout set { if (_flyout != null && value == null) - throw new ArgumentNullException("value", "Flyout cannot be set to null once a value is set"); + throw new ArgumentNullException(nameof(value), "Flyout cannot be set to null once a value is set"); if (string.IsNullOrEmpty(value.Title)) throw new InvalidOperationException("Title property must be set on Flyout page"); diff --git a/src/Controls/src/Core/FocusEventArgs.cs b/src/Controls/src/Core/FocusEventArgs.cs index e88e94525b14..462ad437be60 100644 --- a/src/Controls/src/Core/FocusEventArgs.cs +++ b/src/Controls/src/Core/FocusEventArgs.cs @@ -10,7 +10,7 @@ public class FocusEventArgs : EventArgs public FocusEventArgs(VisualElement visualElement, bool isFocused) { if (visualElement == null) - throw new ArgumentNullException("visualElement"); + throw new ArgumentNullException(nameof(visualElement)); VisualElement = visualElement; IsFocused = isFocused; diff --git a/src/Controls/src/Core/FontImageSource.cs b/src/Controls/src/Core/FontImageSource.cs index 06cd9e5454bf..849f84228654 100644 --- a/src/Controls/src/Core/FontImageSource.cs +++ b/src/Controls/src/Core/FontImageSource.cs @@ -56,7 +56,7 @@ public double Size /// Bindable property for . public static readonly BindableProperty FontAutoScalingEnabledProperty = - BindableProperty.Create("FontAutoScalingEnabled", typeof(bool), typeof(FontImageSource), false, + BindableProperty.Create(nameof(FontAutoScalingEnabled), typeof(bool), typeof(FontImageSource), false, propertyChanged: (b, o, n) => ((FontImageSource)b).OnSourceChanged()); public bool FontAutoScalingEnabled diff --git a/src/Controls/src/Core/Frame/Frame.cs b/src/Controls/src/Core/Frame/Frame.cs index b99e8556599e..581f2f9c940b 100644 --- a/src/Controls/src/Core/Frame/Frame.cs +++ b/src/Controls/src/Core/Frame/Frame.cs @@ -13,7 +13,7 @@ public partial class Frame : ContentView, IElementConfiguration, IPadding public static readonly BindableProperty BorderColorProperty = BorderElement.BorderColorProperty; /// Bindable property for . - public static readonly BindableProperty HasShadowProperty = BindableProperty.Create("HasShadow", typeof(bool), typeof(Frame), true); + public static readonly BindableProperty HasShadowProperty = BindableProperty.Create(nameof(HasShadow), typeof(bool), typeof(Frame), true); /// Bindable property for . public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(Frame), -1.0f, diff --git a/src/Controls/src/Core/HtmlWebViewSource.cs b/src/Controls/src/Core/HtmlWebViewSource.cs index ec0c4faebe9c..0359cded4ea8 100644 --- a/src/Controls/src/Core/HtmlWebViewSource.cs +++ b/src/Controls/src/Core/HtmlWebViewSource.cs @@ -7,11 +7,11 @@ namespace Microsoft.Maui.Controls public class HtmlWebViewSource : WebViewSource { /// Bindable property for . - public static readonly BindableProperty HtmlProperty = BindableProperty.Create("Html", typeof(string), typeof(HtmlWebViewSource), default(string), + public static readonly BindableProperty HtmlProperty = BindableProperty.Create(nameof(Html), typeof(string), typeof(HtmlWebViewSource), default(string), propertyChanged: (bindable, oldvalue, newvalue) => ((HtmlWebViewSource)bindable).OnSourceChanged()); /// Bindable property for . - public static readonly BindableProperty BaseUrlProperty = BindableProperty.Create("BaseUrl", typeof(string), typeof(HtmlWebViewSource), default(string), + public static readonly BindableProperty BaseUrlProperty = BindableProperty.Create(nameof(BaseUrl), typeof(string), typeof(HtmlWebViewSource), default(string), propertyChanged: (bindable, oldvalue, newvalue) => ((HtmlWebViewSource)bindable).OnSourceChanged()); /// diff --git a/src/Controls/src/Core/Interactivity/AttachedCollection.cs b/src/Controls/src/Core/Interactivity/AttachedCollection.cs index 2a53b1ddf4e5..35f62ce3f740 100644 --- a/src/Controls/src/Core/Interactivity/AttachedCollection.cs +++ b/src/Controls/src/Core/Interactivity/AttachedCollection.cs @@ -24,7 +24,7 @@ public AttachedCollection(IList list) : base(list) public void AttachTo(BindableObject bindable) { if (bindable == null) - throw new ArgumentNullException("bindable"); + throw new ArgumentNullException(nameof(bindable)); OnAttachedTo(bindable); } diff --git a/src/Controls/src/Core/Interactivity/TriggerAction.cs b/src/Controls/src/Core/Interactivity/TriggerAction.cs index 3315d5427610..c81ca572754f 100644 --- a/src/Controls/src/Core/Interactivity/TriggerAction.cs +++ b/src/Controls/src/Core/Interactivity/TriggerAction.cs @@ -8,7 +8,7 @@ public abstract class TriggerAction internal TriggerAction(Type associatedType) { if (associatedType == null) - throw new ArgumentNullException("associatedType"); + throw new ArgumentNullException(nameof(associatedType)); AssociatedType = associatedType; } diff --git a/src/Controls/src/Core/Interactivity/TriggerBase.cs b/src/Controls/src/Core/Interactivity/TriggerBase.cs index 2c07341d35f8..ce57e898e258 100644 --- a/src/Controls/src/Core/Interactivity/TriggerBase.cs +++ b/src/Controls/src/Core/Interactivity/TriggerBase.cs @@ -67,7 +67,7 @@ void IAttachedObject.AttachTo(BindableObject bindable) IsSealed = true; if (bindable == null) - throw new ArgumentNullException("bindable"); + throw new ArgumentNullException(nameof(bindable)); if (!TargetType.IsInstanceOfType(bindable)) throw new InvalidOperationException("bindable not an instance of AssociatedType"); OnAttachedTo(bindable); @@ -76,7 +76,7 @@ void IAttachedObject.AttachTo(BindableObject bindable) void IAttachedObject.DetachFrom(BindableObject bindable) { if (bindable == null) - throw new ArgumentNullException("bindable"); + throw new ArgumentNullException(nameof(bindable)); OnDetachingFrom(bindable); } diff --git a/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs b/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs index e136f1dc38a4..68a785355a72 100644 --- a/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs +++ b/src/Controls/src/Core/Internals/NotifyCollectionChangedEventArgsExtensions.cs @@ -25,13 +25,13 @@ public static void Apply(this NotifyCollectionChangedEventArgs self, ILis public static NotifyCollectionChangedAction Apply(this NotifyCollectionChangedEventArgs self, Action insert, Action removeAt, Action reset) { if (self == null) - throw new ArgumentNullException("self"); + throw new ArgumentNullException(nameof(self)); if (reset == null) - throw new ArgumentNullException("reset"); + throw new ArgumentNullException(nameof(reset)); if (insert == null) - throw new ArgumentNullException("insert"); + throw new ArgumentNullException(nameof(insert)); if (removeAt == null) - throw new ArgumentNullException("removeAt"); + throw new ArgumentNullException(nameof(removeAt)); switch (self.Action) { diff --git a/src/Controls/src/Core/Items/ReorderableItemsView.cs b/src/Controls/src/Core/Items/ReorderableItemsView.cs index 35f57744deff..1f0ff80fb21f 100644 --- a/src/Controls/src/Core/Items/ReorderableItemsView.cs +++ b/src/Controls/src/Core/Items/ReorderableItemsView.cs @@ -9,7 +9,7 @@ public class ReorderableItemsView : GroupableItemsView public event EventHandler ReorderCompleted; /// Bindable property for . - public static readonly BindableProperty CanMixGroupsProperty = BindableProperty.Create("CanMixGroups", typeof(bool), typeof(ReorderableItemsView), false); + public static readonly BindableProperty CanMixGroupsProperty = BindableProperty.Create(nameof(CanMixGroups), typeof(bool), typeof(ReorderableItemsView), false); public bool CanMixGroups { get { return (bool)GetValue(CanMixGroupsProperty); } @@ -17,7 +17,7 @@ public bool CanMixGroups } /// Bindable property for . - public static readonly BindableProperty CanReorderItemsProperty = BindableProperty.Create("CanReorderItems", typeof(bool), typeof(ReorderableItemsView), false); + public static readonly BindableProperty CanReorderItemsProperty = BindableProperty.Create(nameof(CanReorderItems), typeof(bool), typeof(ReorderableItemsView), false); public bool CanReorderItems { get { return (bool)GetValue(CanReorderItemsProperty); } diff --git a/src/Controls/src/Core/Label/Label.cs b/src/Controls/src/Core/Label/Label.cs index 8dbf3e288ad3..cf90933bbb35 100644 --- a/src/Controls/src/Core/Label/Label.cs +++ b/src/Controls/src/Core/Label/Label.cs @@ -18,7 +18,7 @@ public partial class Label : View, IFontElement, ITextElement, ITextAlignmentEle public static readonly BindableProperty HorizontalTextAlignmentProperty = TextAlignmentElement.HorizontalTextAlignmentProperty; /// Bindable property for . - public static readonly BindableProperty VerticalTextAlignmentProperty = BindableProperty.Create("VerticalTextAlignment", typeof(TextAlignment), typeof(Label), TextAlignment.Start); + public static readonly BindableProperty VerticalTextAlignmentProperty = BindableProperty.Create(nameof(VerticalTextAlignment), typeof(TextAlignment), typeof(Label), TextAlignment.Start); /// Bindable property for . public static readonly BindableProperty TextColorProperty = TextElement.TextColorProperty; @@ -268,7 +268,7 @@ void ILineHeightElement.OnLineHeightChanged(double oldValue, double newValue) => void OnFormattedTextChanging(object sender, PropertyChangingEventArgs e) { - OnPropertyChanging("FormattedText"); + OnPropertyChanging(nameof(FormattedText)); } void ITextElement.OnTextTransformChanged(TextTransform oldValue, TextTransform newValue) => @@ -276,7 +276,7 @@ void ITextElement.OnTextTransformChanged(TextTransform oldValue, TextTransform n void OnFormattedTextChanged(object sender, PropertyChangedEventArgs e) { - OnPropertyChanged("FormattedText"); + OnPropertyChanged(nameof(FormattedText)); InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged); } diff --git a/src/Controls/src/Core/Layout/Grid.cs b/src/Controls/src/Core/Layout/Grid.cs index 805c224bc37d..f25cd04f30f7 100644 --- a/src/Controls/src/Core/Layout/Grid.cs +++ b/src/Controls/src/Core/Layout/Grid.cs @@ -12,7 +12,7 @@ public class Grid : Layout, IGridLayout readonly Dictionary _viewInfo = new(); /// Bindable property for . - public static readonly BindableProperty ColumnDefinitionsProperty = BindableProperty.Create("ColumnDefinitions", + public static readonly BindableProperty ColumnDefinitionsProperty = BindableProperty.Create(nameof(ColumnDefinitions), typeof(ColumnDefinitionCollection), typeof(Grid), null, validateValue: (bindable, value) => value != null, propertyChanged: UpdateSizeChangedHandlers, defaultValueCreator: bindable => { @@ -22,7 +22,7 @@ public class Grid : Layout, IGridLayout }); /// Bindable property for . - public static readonly BindableProperty RowDefinitionsProperty = BindableProperty.Create("RowDefinitions", + public static readonly BindableProperty RowDefinitionsProperty = BindableProperty.Create(nameof(RowDefinitions), typeof(RowDefinitionCollection), typeof(Grid), null, validateValue: (bindable, value) => value != null, propertyChanged: UpdateSizeChangedHandlers, defaultValueCreator: bindable => { @@ -32,11 +32,11 @@ public class Grid : Layout, IGridLayout }); /// Bindable property for . - public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create("RowSpacing", typeof(double), + public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create(nameof(RowSpacing), typeof(double), typeof(Grid), 0d, propertyChanged: Invalidate); /// Bindable property for . - public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create("ColumnSpacing", typeof(double), + public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create(nameof(ColumnSpacing), typeof(double), typeof(Grid), 0d, propertyChanged: Invalidate); #region Row/Column/Span Attached Properties diff --git a/src/Controls/src/Core/LayoutAlignmentExtensions.cs b/src/Controls/src/Core/LayoutAlignmentExtensions.cs index 50c59fe8ef1a..2df6ccbc7bf4 100644 --- a/src/Controls/src/Core/LayoutAlignmentExtensions.cs +++ b/src/Controls/src/Core/LayoutAlignmentExtensions.cs @@ -15,7 +15,7 @@ public static double ToDouble(this LayoutAlignment align) case LayoutAlignment.End: return 1; } - throw new ArgumentOutOfRangeException("align"); + throw new ArgumentOutOfRangeException(nameof(align)); } } } \ No newline at end of file diff --git a/src/Controls/src/Core/LegacyLayouts/Grid.cs b/src/Controls/src/Core/LegacyLayouts/Grid.cs index 99f5bd7342a4..7d2caf663181 100644 --- a/src/Controls/src/Core/LegacyLayouts/Grid.cs +++ b/src/Controls/src/Core/LegacyLayouts/Grid.cs @@ -25,15 +25,15 @@ public partial class Grid : Layout, IGridController, IElementConfiguration public static readonly BindableProperty ColumnSpanProperty = BindableProperty.CreateAttached("ColumnSpan", typeof(int), typeof(Grid), 1, validateValue: (bindable, value) => (int)value >= 1); /// Bindable property for . - public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create("RowSpacing", typeof(double), typeof(Grid), 6d, + public static readonly BindableProperty RowSpacingProperty = BindableProperty.Create(nameof(RowSpacing), typeof(double), typeof(Grid), 6d, propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged)); /// Bindable property for . - public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create("ColumnSpacing", typeof(double), typeof(Grid), 6d, + public static readonly BindableProperty ColumnSpacingProperty = BindableProperty.Create(nameof(ColumnSpacing), typeof(double), typeof(Grid), 6d, propertyChanged: (bindable, oldValue, newValue) => ((Grid)bindable).InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged)); /// Bindable property for . - public static readonly BindableProperty ColumnDefinitionsProperty = BindableProperty.Create("ColumnDefinitions", typeof(ColumnDefinitionCollection), typeof(Grid), null, + public static readonly BindableProperty ColumnDefinitionsProperty = BindableProperty.Create(nameof(ColumnDefinitions), typeof(ColumnDefinitionCollection), typeof(Grid), null, validateValue: (bindable, value) => value != null, propertyChanged: (bindable, oldvalue, newvalue) => { if (oldvalue != null) @@ -49,7 +49,7 @@ public partial class Grid : Layout, IGridController, IElementConfiguration }); /// Bindable property for . - public static readonly BindableProperty RowDefinitionsProperty = BindableProperty.Create("RowDefinitions", typeof(RowDefinitionCollection), typeof(Grid), null, + public static readonly BindableProperty RowDefinitionsProperty = BindableProperty.Create(nameof(RowDefinitions), typeof(RowDefinitionCollection), typeof(Grid), null, validateValue: (bindable, value) => value != null, propertyChanged: (bindable, oldvalue, newvalue) => { if (oldvalue != null) @@ -311,24 +311,24 @@ public GridElementCollection(ObservableCollection inner, Grid parent) : public void Add(View view, int left, int top) { if (left < 0) - throw new ArgumentOutOfRangeException("left"); + throw new ArgumentOutOfRangeException(nameof(left)); if (top < 0) - throw new ArgumentOutOfRangeException("top"); + throw new ArgumentOutOfRangeException(nameof(top)); Add(view, left, left + 1, top, top + 1); } public void Add(View view, int left, int right, int top, int bottom) { if (left < 0) - throw new ArgumentOutOfRangeException("left"); + throw new ArgumentOutOfRangeException(nameof(left)); if (top < 0) - throw new ArgumentOutOfRangeException("top"); + throw new ArgumentOutOfRangeException(nameof(top)); if (left >= right) - throw new ArgumentOutOfRangeException("right"); + throw new ArgumentOutOfRangeException(nameof(right)); if (top >= bottom) - throw new ArgumentOutOfRangeException("bottom"); + throw new ArgumentOutOfRangeException(nameof(bottom)); if (view == null) - throw new ArgumentNullException("view"); + throw new ArgumentNullException(nameof(view)); SetRow(view, top); SetRowSpan(view, bottom - top); @@ -341,7 +341,7 @@ public void Add(View view, int left, int right, int top, int bottom) public void AddHorizontal(IEnumerable views) { if (views == null) - throw new ArgumentNullException("views"); + throw new ArgumentNullException(nameof(views)); views.ForEach(AddHorizontal); } @@ -349,7 +349,7 @@ public void AddHorizontal(IEnumerable views) public void AddHorizontal(View view) { if (view == null) - throw new ArgumentNullException("view"); + throw new ArgumentNullException(nameof(view)); var rows = RowCount(); var columns = ColumnCount(); @@ -364,7 +364,7 @@ public void AddHorizontal(View view) public void AddVertical(IEnumerable views) { if (views == null) - throw new ArgumentNullException("views"); + throw new ArgumentNullException(nameof(views)); views.ForEach(AddVertical); } @@ -372,7 +372,7 @@ public void AddVertical(IEnumerable views) public void AddVertical(View view) { if (view == null) - throw new ArgumentNullException("view"); + throw new ArgumentNullException(nameof(view)); var rows = RowCount(); var columns = ColumnCount(); diff --git a/src/Controls/src/Core/ListProxy.cs b/src/Controls/src/Core/ListProxy.cs index 8d3a5bd461b1..eb217a0d96dc 100644 --- a/src/Controls/src/Core/ListProxy.cs +++ b/src/Controls/src/Core/ListProxy.cs @@ -131,7 +131,7 @@ public object this[int index] { object value; if (!TryGetValue(index, out value)) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); return value; } diff --git a/src/Controls/src/Core/ListView/ListView.cs b/src/Controls/src/Core/ListView/ListView.cs index fe4053865259..881317625e7f 100644 --- a/src/Controls/src/Core/ListView/ListView.cs +++ b/src/Controls/src/Core/ListView/ListView.cs @@ -24,53 +24,53 @@ public class ListView : ItemsView, IListViewController, IElementConfigurat IReadOnlyList IVisualTreeElement.GetVisualChildren() => _visualChildren; /// Bindable property for . - public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create("IsPullToRefreshEnabled", typeof(bool), typeof(ListView), false); + public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create(nameof(IsPullToRefreshEnabled), typeof(bool), typeof(ListView), false); /// Bindable property for . - public static readonly BindableProperty IsRefreshingProperty = BindableProperty.Create("IsRefreshing", typeof(bool), typeof(ListView), false, BindingMode.TwoWay); + public static readonly BindableProperty IsRefreshingProperty = BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(ListView), false, BindingMode.TwoWay); /// Bindable property for . - public static readonly BindableProperty RefreshCommandProperty = BindableProperty.Create("RefreshCommand", typeof(ICommand), typeof(ListView), null, propertyChanged: OnRefreshCommandChanged); + public static readonly BindableProperty RefreshCommandProperty = BindableProperty.Create(nameof(RefreshCommand), typeof(ICommand), typeof(ListView), null, propertyChanged: OnRefreshCommandChanged); /// Bindable property for . - public static readonly BindableProperty HeaderProperty = BindableProperty.Create("Header", typeof(object), typeof(ListView), null, propertyChanged: OnHeaderChanged); + public static readonly BindableProperty HeaderProperty = BindableProperty.Create(nameof(Header), typeof(object), typeof(ListView), null, propertyChanged: OnHeaderChanged); /// Bindable property for . - public static readonly BindableProperty HeaderTemplateProperty = BindableProperty.Create("HeaderTemplate", typeof(DataTemplate), typeof(ListView), null, propertyChanged: OnHeaderTemplateChanged, + public static readonly BindableProperty HeaderTemplateProperty = BindableProperty.Create(nameof(HeaderTemplate), typeof(DataTemplate), typeof(ListView), null, propertyChanged: OnHeaderTemplateChanged, validateValue: ValidateHeaderFooterTemplate); /// Bindable property for . - public static readonly BindableProperty FooterProperty = BindableProperty.Create("Footer", typeof(object), typeof(ListView), null, propertyChanged: OnFooterChanged); + public static readonly BindableProperty FooterProperty = BindableProperty.Create(nameof(Footer), typeof(object), typeof(ListView), null, propertyChanged: OnFooterChanged); /// Bindable property for . - public static readonly BindableProperty FooterTemplateProperty = BindableProperty.Create("FooterTemplate", typeof(DataTemplate), typeof(ListView), null, propertyChanged: OnFooterTemplateChanged, + public static readonly BindableProperty FooterTemplateProperty = BindableProperty.Create(nameof(FooterTemplate), typeof(DataTemplate), typeof(ListView), null, propertyChanged: OnFooterTemplateChanged, validateValue: ValidateHeaderFooterTemplate); /// Bindable property for . - public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(ListView), null, BindingMode.OneWayToSource, + public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(ListView), null, BindingMode.OneWayToSource, propertyChanged: OnSelectedItemChanged); /// Bindable property for . public static readonly BindableProperty SelectionModeProperty = BindableProperty.Create(nameof(SelectionMode), typeof(ListViewSelectionMode), typeof(ListView), ListViewSelectionMode.Single); /// Bindable property for . - public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create("HasUnevenRows", typeof(bool), typeof(ListView), false); + public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(ListView), false); /// Bindable property for . - public static readonly BindableProperty RowHeightProperty = BindableProperty.Create("RowHeight", typeof(int), typeof(ListView), -1); + public static readonly BindableProperty RowHeightProperty = BindableProperty.Create(nameof(RowHeight), typeof(int), typeof(ListView), -1); /// Bindable property for . - public static readonly BindableProperty GroupHeaderTemplateProperty = BindableProperty.Create("GroupHeaderTemplate", typeof(DataTemplate), typeof(ListView), null, + public static readonly BindableProperty GroupHeaderTemplateProperty = BindableProperty.Create(nameof(GroupHeaderTemplate), typeof(DataTemplate), typeof(ListView), null, propertyChanged: OnGroupHeaderTemplateChanged); /// Bindable property for . - public static readonly BindableProperty IsGroupingEnabledProperty = BindableProperty.Create("IsGroupingEnabled", typeof(bool), typeof(ListView), false); + public static readonly BindableProperty IsGroupingEnabledProperty = BindableProperty.Create(nameof(IsGroupingEnabled), typeof(bool), typeof(ListView), false); /// Bindable property for . - public static readonly BindableProperty SeparatorVisibilityProperty = BindableProperty.Create("SeparatorVisibility", typeof(SeparatorVisibility), typeof(ListView), SeparatorVisibility.Default); + public static readonly BindableProperty SeparatorVisibilityProperty = BindableProperty.Create(nameof(SeparatorVisibility), typeof(SeparatorVisibility), typeof(ListView), SeparatorVisibility.Default); /// Bindable property for . - public static readonly BindableProperty SeparatorColorProperty = BindableProperty.Create("SeparatorColor", typeof(Color), typeof(ListView), null); + public static readonly BindableProperty SeparatorColorProperty = BindableProperty.Create(nameof(SeparatorColor), typeof(Color), typeof(ListView), null); /// Bindable property for . public static readonly BindableProperty RefreshControlColorProperty = BindableProperty.Create(nameof(RefreshControlColor), typeof(Color), typeof(ListView), null); @@ -384,7 +384,7 @@ public void EndRefresh() public void ScrollTo(object item, ScrollToPosition position, bool animated) { if (!Enum.IsDefined(typeof(ScrollToPosition), position)) - throw new ArgumentException("position is not a valid ScrollToPosition", "position"); + throw new ArgumentException("position is not a valid ScrollToPosition", nameof(position)); var args = new ScrollToRequestedEventArgs(item, position, animated); if (IsPlatformEnabled) @@ -399,7 +399,7 @@ public void ScrollTo(object item, object group, ScrollToPosition position, bool if (!IsGroupingEnabled) throw new InvalidOperationException("Grouping is not enabled"); if (!Enum.IsDefined(typeof(ScrollToPosition), position)) - throw new ArgumentException("position is not a valid ScrollToPosition", "position"); + throw new ArgumentException("position is not a valid ScrollToPosition", nameof(position)); var args = new ScrollToRequestedEventArgs(item, group, position, animated); if (IsPlatformEnabled) diff --git a/src/Controls/src/Core/LockingSemaphore.cs b/src/Controls/src/Core/LockingSemaphore.cs index b0531fb7a24a..cb6edde1d24e 100644 --- a/src/Controls/src/Core/LockingSemaphore.cs +++ b/src/Controls/src/Core/LockingSemaphore.cs @@ -15,7 +15,7 @@ internal class LockingSemaphore public LockingSemaphore(int initialCount) { if (initialCount < 0) - throw new ArgumentOutOfRangeException("initialCount"); + throw new ArgumentOutOfRangeException(nameof(initialCount)); _currentCount = initialCount; } diff --git a/src/Controls/src/Core/MergedStyle.cs b/src/Controls/src/Core/MergedStyle.cs index 4dc32494deac..b96ae59d00db 100644 --- a/src/Controls/src/Core/MergedStyle.cs +++ b/src/Controls/src/Core/MergedStyle.cs @@ -152,7 +152,7 @@ void RegisterImplicitStyles() Type type = TargetType; while (true) { - BindableProperty implicitStyleProperty = BindableProperty.Create("ImplicitStyle", typeof(Style), typeof(NavigableElement), default(Style), + BindableProperty implicitStyleProperty = BindableProperty.Create(nameof(ImplicitStyle), typeof(Style), typeof(NavigableElement), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => OnImplicitStyleChanged()); _implicitStyles.Add(implicitStyleProperty); Target.SetDynamicResource(implicitStyleProperty, type.FullName); @@ -170,7 +170,7 @@ internal void ReRegisterImplicitStyles(string fallbackTypeName) _implicitStyles.Clear(); //Register the fallback - BindableProperty implicitStyleProperty = BindableProperty.Create("ImplicitStyle", typeof(Style), typeof(NavigableElement), default(Style), + BindableProperty implicitStyleProperty = BindableProperty.Create(nameof(ImplicitStyle), typeof(Style), typeof(NavigableElement), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => OnImplicitStyleChanged()); _implicitStyles.Add(implicitStyleProperty); Target.SetDynamicResource(implicitStyleProperty, fallbackTypeName); diff --git a/src/Controls/src/Core/MultiPage.cs b/src/Controls/src/Core/MultiPage.cs index ee42ac77dfaf..8ebf34234626 100644 --- a/src/Controls/src/Core/MultiPage.cs +++ b/src/Controls/src/Core/MultiPage.cs @@ -16,13 +16,13 @@ namespace Microsoft.Maui.Controls public abstract class MultiPage<[DynamicallyAccessedMembers(BindableProperty.DeclaringTypeMembers)] T> : Page, IViewContainer, IPageContainer, IItemsView, IMultiPageController where T : Page { /// Bindable property for . - public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(IEnumerable), typeof(MultiPage<>), null); + public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(MultiPage<>), null); /// Bindable property for . - public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create("ItemTemplate", typeof(DataTemplate), typeof(MultiPage<>), null); + public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(MultiPage<>), null); /// Bindable property for . - public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create("SelectedItem", typeof(object), typeof(MultiPage<>), null, BindingMode.TwoWay); + public static readonly BindableProperty SelectedItemProperty = BindableProperty.Create(nameof(SelectedItem), typeof(object), typeof(MultiPage<>), null, BindingMode.TwoWay); internal static readonly BindableProperty IndexProperty = BindableProperty.Create("Index", typeof(int), typeof(Page), -1); @@ -178,7 +178,7 @@ protected virtual void UnhookContent(T content) public static int GetIndex(T page) { if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); return (int)page.GetValue(IndexProperty); } @@ -198,7 +198,7 @@ public T GetPageByIndex(int index) public static void SetIndex(Page page, int index) { if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); page.SetValue(IndexProperty, index); } diff --git a/src/Controls/src/Core/NavigationEventArgs.cs b/src/Controls/src/Core/NavigationEventArgs.cs index 3097755b1195..ea4488dd35e6 100644 --- a/src/Controls/src/Core/NavigationEventArgs.cs +++ b/src/Controls/src/Core/NavigationEventArgs.cs @@ -10,7 +10,7 @@ public class NavigationEventArgs : EventArgs public NavigationEventArgs(Page page) { if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); Page = page; } diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index 25375d7756a4..9a0cc0f6bf2d 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -43,7 +43,7 @@ public partial class NavigationPage : Page, IPageContainer, IBarElement, I public static readonly BindableProperty TitleViewProperty = BindableProperty.CreateAttached("TitleView", typeof(View), typeof(NavigationPage), null, propertyChanging: TitleViewPropertyChanging, propertyChanged: (bo, oldV, newV) => bo.AddRemoveLogicalChildren(oldV, newV)); - static readonly BindablePropertyKey CurrentPagePropertyKey = BindableProperty.CreateReadOnly("CurrentPage", typeof(Page), typeof(NavigationPage), null, propertyChanged: OnCurrentPageChanged); + static readonly BindablePropertyKey CurrentPagePropertyKey = BindableProperty.CreateReadOnly(nameof(CurrentPage), typeof(Page), typeof(NavigationPage), null, propertyChanged: OnCurrentPageChanged); /// Bindable property for . public static readonly BindableProperty CurrentPageProperty = CurrentPagePropertyKey.BindableProperty; @@ -171,7 +171,7 @@ public static string GetBackButtonTitle(BindableObject page) public static bool GetHasBackButton(Page page) { if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); return (bool)page.GetValue(HasBackButtonProperty); } @@ -332,7 +332,7 @@ public static void SetBackButtonTitle(BindableObject page, string value) public static void SetHasBackButton(Page page, bool value) { if (page == null) - throw new ArgumentNullException("page"); + throw new ArgumentNullException(nameof(page)); page.SetValue(HasBackButtonProperty, value); } diff --git a/src/Controls/src/Core/ObservableList.cs b/src/Controls/src/Core/ObservableList.cs index 501a6190274f..a400c11a41d8 100644 --- a/src/Controls/src/Core/ObservableList.cs +++ b/src/Controls/src/Core/ObservableList.cs @@ -15,7 +15,7 @@ internal class ObservableList : ObservableCollection public void AddRange(IEnumerable range) { if (range == null) - throw new ArgumentNullException("range"); + throw new ArgumentNullException(nameof(range)); List items = range.ToList(); int index = Items.Count; @@ -28,9 +28,9 @@ public void AddRange(IEnumerable range) public void InsertRange(int index, IEnumerable range) { if (index < 0 || index > Count) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); if (range == null) - throw new ArgumentNullException("range"); + throw new ArgumentNullException(nameof(range)); int originalIndex = index; @@ -44,9 +44,9 @@ public void InsertRange(int index, IEnumerable range) public void Move(int oldIndex, int newIndex, int count) { if (oldIndex < 0 || oldIndex + count > Count) - throw new ArgumentOutOfRangeException("oldIndex"); + throw new ArgumentOutOfRangeException(nameof(oldIndex)); if (newIndex < 0 || newIndex + count > Count) - throw new ArgumentOutOfRangeException("newIndex"); + throw new ArgumentOutOfRangeException(nameof(newIndex)); var items = new List(count); for (var i = 0; i < count; i++) @@ -69,7 +69,7 @@ public void Move(int oldIndex, int newIndex, int count) public void RemoveAt(int index, int count) { if (index < 0 || index + count > Count) - throw new ArgumentOutOfRangeException("index"); + throw new ArgumentOutOfRangeException(nameof(index)); T[] items = Items.Skip(index).Take(count).ToArray(); for (int i = index; i < count; i++) @@ -81,7 +81,7 @@ public void RemoveAt(int index, int count) public void RemoveRange(IEnumerable range) { if (range == null) - throw new ArgumentNullException("range"); + throw new ArgumentNullException(nameof(range)); List items = range.ToList(); foreach (T item in items) @@ -93,12 +93,12 @@ public void RemoveRange(IEnumerable range) public void ReplaceRange(int startIndex, IEnumerable items) { if (items == null) - throw new ArgumentNullException("items"); + throw new ArgumentNullException(nameof(items)); T[] ritems = items.ToArray(); if (startIndex < 0 || startIndex + ritems.Length > Count) - throw new ArgumentOutOfRangeException("startIndex"); + throw new ArgumentOutOfRangeException(nameof(startIndex)); var oldItems = new T[ritems.Length]; for (var i = 0; i < ritems.Length; i++) diff --git a/src/Controls/src/Core/ObservableWrapper.cs b/src/Controls/src/Core/ObservableWrapper.cs index 2babf5b7fadd..0fc5e10056e7 100644 --- a/src/Controls/src/Core/ObservableWrapper.cs +++ b/src/Controls/src/Core/ObservableWrapper.cs @@ -14,7 +14,7 @@ internal class ObservableWrapper : IList, IList, I public ObservableWrapper(ObservableCollection list) { if (list == null) - throw new ArgumentNullException("list"); + throw new ArgumentNullException(nameof(list)); _list = list; @@ -24,7 +24,7 @@ public ObservableWrapper(ObservableCollection list) public void Add(TRestrict item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); if (IsReadOnly) throw new NotSupportedException("The collection is read-only."); @@ -88,7 +88,7 @@ public int Count public bool Remove(TRestrict item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); if (IsReadOnly) throw new NotSupportedException("The collection is read-only."); @@ -130,7 +130,7 @@ public int IndexOf(TRestrict value) public void Insert(int index, TRestrict item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); if (IsReadOnly) throw new NotSupportedException("The collection is read-only."); diff --git a/src/Controls/src/Core/OrderedDictionary.cs b/src/Controls/src/Core/OrderedDictionary.cs index d0a027d589ce..ac935eadb110 100644 --- a/src/Controls/src/Core/OrderedDictionary.cs +++ b/src/Controls/src/Core/OrderedDictionary.cs @@ -74,7 +74,7 @@ public OrderedDictionary(ICollection> dictionary) : t public OrderedDictionary(ICollection> dictionary, IEqualityComparer equalityComparer) : this(dictionary != null ? dictionary.Count : 0, equalityComparer) { if (dictionary == null) - throw new ArgumentNullException("dictionary"); + throw new ArgumentNullException(nameof(dictionary)); foreach (KeyValuePair kvp in dictionary) Add(kvp.Key, kvp.Value); @@ -124,11 +124,11 @@ bool ICollection>.Contains(KeyValuePair void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (Count > array.Length - arrayIndex) throw new ArgumentException("Not enough space in array to copy"); if (arrayIndex < 0) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); for (var i = 0; i < _keyOrder.Count; ++i) { @@ -296,7 +296,7 @@ public bool ContainsValue(TValue value) public int IndexOf(TKey key) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); return _keyOrder.IndexOf(key); } @@ -312,7 +312,7 @@ public int IndexOf(TKey key) public int IndexOf(TKey key, int startIndex) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); return _keyOrder.IndexOf(key, startIndex); } @@ -335,7 +335,7 @@ public int IndexOf(TKey key, int startIndex) public int IndexOf(TKey key, int startIndex, int count) { if (key == null) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); return _keyOrder.IndexOf(key, startIndex, count); } @@ -391,11 +391,11 @@ public bool Contains(TValue item) public void CopyTo(TValue[] array, int arrayIndex) { if (array == null) - throw new ArgumentNullException("array"); + throw new ArgumentNullException(nameof(array)); if (Count > array.Length - arrayIndex) throw new ArgumentException("Not enough space in array to copy"); if (arrayIndex < 0 || arrayIndex > array.Length) - throw new ArgumentOutOfRangeException("arrayIndex"); + throw new ArgumentOutOfRangeException(nameof(arrayIndex)); for (var i = 0; i < _odict.Count; ++i) array[arrayIndex++] = _odict[i]; diff --git a/src/Controls/src/Core/Page/Page.cs b/src/Controls/src/Core/Page/Page.cs index 4d5797987ab6..622e960087ba 100644 --- a/src/Controls/src/Core/Page/Page.cs +++ b/src/Controls/src/Core/Page/Page.cs @@ -47,19 +47,19 @@ public partial class Page : VisualElement, ILayout, IPageController, IElementCon /// For internal use only. This API can be changed or removed without notice at any time. public const string ActionSheetSignalName = "Microsoft.Maui.Controls.ShowActionSheet"; - internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create("IgnoresContainerArea", typeof(bool), typeof(Page), false); + internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create(nameof(IgnoresContainerArea), typeof(bool), typeof(Page), false); /// Bindable property for . public static readonly BindableProperty BackgroundImageSourceProperty = BindableProperty.Create(nameof(BackgroundImageSource), typeof(ImageSource), typeof(Page), default(ImageSource)); /// Bindable property for . - public static readonly BindableProperty IsBusyProperty = BindableProperty.Create("IsBusy", typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged()); + public static readonly BindableProperty IsBusyProperty = BindableProperty.Create(nameof(IsBusy), typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged()); /// Bindable property for . public static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty; /// Bindable property for . - public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(Page), null); + public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(Page), null); /// Bindable property for . public static readonly BindableProperty IconImageSourceProperty = BindableProperty.Create(nameof(IconImageSource), typeof(ImageSource), typeof(Page), default(ImageSource)); diff --git a/src/Controls/src/Core/PanGestureRecognizer.cs b/src/Controls/src/Core/PanGestureRecognizer.cs index 74b0be7f363f..667f149b8be6 100644 --- a/src/Controls/src/Core/PanGestureRecognizer.cs +++ b/src/Controls/src/Core/PanGestureRecognizer.cs @@ -12,7 +12,7 @@ public class PanGestureRecognizer : GestureRecognizer, IPanGestureController public static AutoId CurrentId { get; } = new(); /// Bindable property for . - public static readonly BindableProperty TouchPointsProperty = BindableProperty.Create("TouchPoints", typeof(int), typeof(PanGestureRecognizer), 1); + public static readonly BindableProperty TouchPointsProperty = BindableProperty.Create(nameof(TouchPoints), typeof(int), typeof(PanGestureRecognizer), 1); /// public int TouchPoints diff --git a/src/Controls/src/Core/Platform/Windows/Extensions/FrameworkElementExtensions.cs b/src/Controls/src/Core/Platform/Windows/Extensions/FrameworkElementExtensions.cs index 43a232fcc22f..4598d227ba9d 100644 --- a/src/Controls/src/Core/Platform/Windows/Extensions/FrameworkElementExtensions.cs +++ b/src/Controls/src/Core/Platform/Windows/Extensions/FrameworkElementExtensions.cs @@ -22,7 +22,7 @@ internal static class FrameworkElementExtensions public static WBrush GetForeground(this FrameworkElement element) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); return (WBrush)element.GetValue(GetForegroundProperty(element)); } @@ -57,7 +57,7 @@ public static void RestoreForegroundCache(this FrameworkElement element, object public static void SetForeground(this FrameworkElement element, WBrush foregroundBrush) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); element.SetValue(GetForegroundProperty(element), foregroundBrush); } @@ -65,7 +65,7 @@ public static void SetForeground(this FrameworkElement element, WBrush foregroun public static void SetForeground(this FrameworkElement element, WBinding binding) { if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); element.SetBinding(GetForegroundProperty(element), binding); } diff --git a/src/Controls/src/Core/Platform/Windows/Extensions/VisualElementExtensions.cs b/src/Controls/src/Core/Platform/Windows/Extensions/VisualElementExtensions.cs index 9dcff5db28e9..933062a0a41e 100644 --- a/src/Controls/src/Core/Platform/Windows/Extensions/VisualElementExtensions.cs +++ b/src/Controls/src/Core/Platform/Windows/Extensions/VisualElementExtensions.cs @@ -15,7 +15,7 @@ public static void UpdateAccessKey(this FrameworkElement platformView, IView vie internal static void Cleanup(this Element self) { if (self == null) - throw new ArgumentNullException("self"); + throw new ArgumentNullException(nameof(self)); foreach (Element element in self.Descendants()) { diff --git a/src/Controls/src/Core/ScrollView/ScrollView.cs b/src/Controls/src/Core/ScrollView/ScrollView.cs index 7f184b822d11..f4e555d44b1d 100644 --- a/src/Controls/src/Core/ScrollView/ScrollView.cs +++ b/src/Controls/src/Core/ScrollView/ScrollView.cs @@ -109,19 +109,19 @@ public void SetScrolledPosition(double x, double y) #endregion IScrollViewController /// Bindable property for . - public static readonly BindableProperty OrientationProperty = BindableProperty.Create("Orientation", typeof(ScrollOrientation), typeof(ScrollView), ScrollOrientation.Vertical); + public static readonly BindableProperty OrientationProperty = BindableProperty.Create(nameof(Orientation), typeof(ScrollOrientation), typeof(ScrollView), ScrollOrientation.Vertical); - static readonly BindablePropertyKey ScrollXPropertyKey = BindableProperty.CreateReadOnly("ScrollX", typeof(double), typeof(ScrollView), 0d); + static readonly BindablePropertyKey ScrollXPropertyKey = BindableProperty.CreateReadOnly(nameof(ScrollX), typeof(double), typeof(ScrollView), 0d); /// Bindable property for . public static readonly BindableProperty ScrollXProperty = ScrollXPropertyKey.BindableProperty; - static readonly BindablePropertyKey ScrollYPropertyKey = BindableProperty.CreateReadOnly("ScrollY", typeof(double), typeof(ScrollView), 0d); + static readonly BindablePropertyKey ScrollYPropertyKey = BindableProperty.CreateReadOnly(nameof(ScrollY), typeof(double), typeof(ScrollView), 0d); /// Bindable property for . public static readonly BindableProperty ScrollYProperty = ScrollYPropertyKey.BindableProperty; - static readonly BindablePropertyKey ContentSizePropertyKey = BindableProperty.CreateReadOnly("ContentSize", typeof(Size), typeof(ScrollView), default(Size)); + static readonly BindablePropertyKey ContentSizePropertyKey = BindableProperty.CreateReadOnly(nameof(ContentSize), typeof(Size), typeof(ScrollView), default(Size)); /// Bindable property for . public static readonly BindableProperty ContentSizeProperty = ContentSizePropertyKey.BindableProperty; @@ -256,13 +256,13 @@ public Task ScrollToAsync(Element element, ScrollToPosition position, bool anima return Task.FromResult(false); if (!Enum.IsDefined(typeof(ScrollToPosition), position)) - throw new ArgumentException("position is not a valid ScrollToPosition", "position"); + throw new ArgumentException("position is not a valid ScrollToPosition", nameof(position)); if (element == null) - throw new ArgumentNullException("element"); + throw new ArgumentNullException(nameof(element)); if (!CheckElementBelongsToScrollViewer(element)) - throw new ArgumentException("element does not belong to this ScrollView", "element"); + throw new ArgumentException("element does not belong to this ScrollView", nameof(element)); var args = new ScrollToRequestedEventArgs(element, position, animated); OnScrollToRequested(args); diff --git a/src/Controls/src/Core/SearchBar/SearchBar.cs b/src/Controls/src/Core/SearchBar/SearchBar.cs index 243a46678ac8..8d8252745785 100644 --- a/src/Controls/src/Core/SearchBar/SearchBar.cs +++ b/src/Controls/src/Core/SearchBar/SearchBar.cs @@ -12,19 +12,19 @@ public partial class SearchBar : InputView, ITextAlignmentElement, ISearchBarCon { /// Bindable property for . public static readonly BindableProperty SearchCommandProperty = BindableProperty.Create( - "SearchCommand", typeof(ICommand), typeof(SearchBar), null, + nameof(SearchCommand), typeof(ICommand), typeof(SearchBar), null, propertyChanging: CommandElement.OnCommandChanging, propertyChanged: CommandElement.OnCommandChanged); /// Bindable property for . public static readonly BindableProperty SearchCommandParameterProperty = BindableProperty.Create( - "SearchCommandParameter", typeof(object), typeof(SearchBar), null, + nameof(SearchCommandParameter), typeof(object), typeof(SearchBar), null, propertyChanged: CommandElement.OnCommandParameterChanged); /// public new static readonly BindableProperty TextProperty = InputView.TextProperty; /// Bindable property for . - public static readonly BindableProperty CancelButtonColorProperty = BindableProperty.Create("CancelButtonColor", typeof(Color), typeof(SearchBar), default(Color)); + public static readonly BindableProperty CancelButtonColorProperty = BindableProperty.Create(nameof(CancelButtonColor), typeof(Color), typeof(SearchBar), default(Color)); /// public new static readonly BindableProperty PlaceholderProperty = InputView.PlaceholderProperty; diff --git a/src/Controls/src/Core/SettersExtensions.cs b/src/Controls/src/Core/SettersExtensions.cs index b1e14979fdd7..59f3239e5bbf 100644 --- a/src/Controls/src/Core/SettersExtensions.cs +++ b/src/Controls/src/Core/SettersExtensions.cs @@ -18,7 +18,7 @@ public static void Add(this IList setters, BindableProperty property, ob public static void AddBinding(this IList setters, BindableProperty property, Binding binding) { if (binding == null) - throw new ArgumentNullException("binding"); + throw new ArgumentNullException(nameof(binding)); setters.Add(new Setter { Property = property, Value = binding }); } @@ -27,7 +27,7 @@ public static void AddBinding(this IList setters, BindableProperty prope public static void AddDynamicResource(this IList setters, BindableProperty property, string key) { if (string.IsNullOrEmpty(key)) - throw new ArgumentNullException("key"); + throw new ArgumentNullException(nameof(key)); setters.Add(new Setter { Property = property, Value = new DynamicResource(key) }); } } diff --git a/src/Controls/src/Core/Shell/NavigableElement.cs b/src/Controls/src/Core/Shell/NavigableElement.cs index 7a6c4d730031..f09bd8080cca 100644 --- a/src/Controls/src/Core/Shell/NavigableElement.cs +++ b/src/Controls/src/Core/Shell/NavigableElement.cs @@ -11,14 +11,14 @@ namespace Microsoft.Maui.Controls public class NavigableElement : Element, INavigationProxy, IStyleSelectable { static readonly BindablePropertyKey NavigationPropertyKey = - BindableProperty.CreateReadOnly("Navigation", typeof(INavigation), typeof(VisualElement), default(INavigation)); + BindableProperty.CreateReadOnly(nameof(Navigation), typeof(INavigation), typeof(VisualElement), default(INavigation)); /// Bindable property for . public static readonly BindableProperty NavigationProperty = NavigationPropertyKey.BindableProperty; /// Bindable property for . public static readonly BindableProperty StyleProperty = - BindableProperty.Create("Style", typeof(Style), typeof(VisualElement), default(Style), + BindableProperty.Create(nameof(Style), typeof(Style), typeof(VisualElement), default(Style), propertyChanged: (bindable, oldvalue, newvalue) => ((NavigableElement)bindable)._mergedStyle.Style = (Style)newvalue); internal readonly MergedStyle _mergedStyle; diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index ad4738e139b3..4a1b1c9dcb6a 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -44,7 +44,7 @@ static void OnBackButonBehaviorPropertyChanged(BindableObject bindable, object o /// Bindable property for attached property FlyoutBehavior. public static readonly BindableProperty FlyoutBehaviorProperty = - BindableProperty.CreateAttached("FlyoutBehavior", typeof(FlyoutBehavior), typeof(Shell), FlyoutBehavior.Flyout, + BindableProperty.CreateAttached(nameof(FlyoutBehavior), typeof(FlyoutBehavior), typeof(Shell), FlyoutBehavior.Flyout, propertyChanged: OnFlyoutBehaviorChanged); /// Bindable property for attached property NavBarIsVisible. @@ -231,17 +231,17 @@ static void OnFlyoutBehaviorChanged(BindableObject bindable, object oldValue, ob /// Bindable property for attached property FlyoutBackdrop. public static readonly BindableProperty FlyoutBackdropProperty = - BindableProperty.CreateAttached("FlyoutBackdrop", typeof(Brush), typeof(Shell), Brush.Default, + BindableProperty.CreateAttached(nameof(FlyoutBackdrop), typeof(Brush), typeof(Shell), Brush.Default, propertyChanged: OnShellAppearanceValueChanged); /// Bindable property for attached property FlyoutWidth. public static readonly BindableProperty FlyoutWidthProperty = - BindableProperty.CreateAttached("FlyoutWidth", typeof(double), typeof(Shell), -1d, + BindableProperty.CreateAttached(nameof(FlyoutWidth), typeof(double), typeof(Shell), -1d, propertyChanged: OnShellAppearanceValueChanged); /// Bindable property for attached property FlyoutHeight. public static readonly BindableProperty FlyoutHeightProperty = - BindableProperty.CreateAttached("FlyoutHeight", typeof(double), typeof(Shell), -1d, + BindableProperty.CreateAttached(nameof(FlyoutHeight), typeof(double), typeof(Shell), -1d, propertyChanged: OnShellAppearanceValueChanged); /// diff --git a/src/Controls/src/Core/StreamImageSource.cs b/src/Controls/src/Core/StreamImageSource.cs index 99aacbcfc74c..cc2aec7d11e8 100644 --- a/src/Controls/src/Core/StreamImageSource.cs +++ b/src/Controls/src/Core/StreamImageSource.cs @@ -10,7 +10,7 @@ namespace Microsoft.Maui.Controls public partial class StreamImageSource : ImageSource, IStreamImageSource { /// Bindable property for . - public static readonly BindableProperty StreamProperty = BindableProperty.Create("Stream", typeof(Func>), typeof(StreamImageSource), + public static readonly BindableProperty StreamProperty = BindableProperty.Create(nameof(Stream), typeof(Func>), typeof(StreamImageSource), default(Func>)); /// diff --git a/src/Controls/src/Core/StreamWrapper.cs b/src/Controls/src/Core/StreamWrapper.cs index a9cd9292fdf1..44b5662a33a8 100644 --- a/src/Controls/src/Core/StreamWrapper.cs +++ b/src/Controls/src/Core/StreamWrapper.cs @@ -21,7 +21,7 @@ public StreamWrapper(Stream wrapped) public StreamWrapper(Stream wrapped, IDisposable additionalDisposable) { if (wrapped == null) - throw new ArgumentNullException("wrapped"); + throw new ArgumentNullException(nameof(wrapped)); _wrapped = wrapped; _additionalDisposable = additionalDisposable; diff --git a/src/Controls/src/Core/SwipeGestureRecognizer.cs b/src/Controls/src/Core/SwipeGestureRecognizer.cs index bc6dde376761..6a968934511b 100644 --- a/src/Controls/src/Core/SwipeGestureRecognizer.cs +++ b/src/Controls/src/Core/SwipeGestureRecognizer.cs @@ -16,13 +16,13 @@ public sealed class SwipeGestureRecognizer : GestureRecognizer, ISwipeGestureCon public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(SwipeGestureRecognizer), null); /// Bindable property for . - public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create("CommandParameter", typeof(object), typeof(SwipeGestureRecognizer), null); + public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(SwipeGestureRecognizer), null); /// Bindable property for . - public static readonly BindableProperty DirectionProperty = BindableProperty.Create("Direction", typeof(SwipeDirection), typeof(SwipeGestureRecognizer), default(SwipeDirection)); + public static readonly BindableProperty DirectionProperty = BindableProperty.Create(nameof(Direction), typeof(SwipeDirection), typeof(SwipeGestureRecognizer), default(SwipeDirection)); /// Bindable property for . - public static readonly BindableProperty ThresholdProperty = BindableProperty.Create("Threshold", typeof(uint), typeof(SwipeGestureRecognizer), DefaultSwipeThreshold); + public static readonly BindableProperty ThresholdProperty = BindableProperty.Create(nameof(Threshold), typeof(uint), typeof(SwipeGestureRecognizer), DefaultSwipeThreshold); /// public ICommand Command diff --git a/src/Controls/src/Core/TableView/TableSectionBase.cs b/src/Controls/src/Core/TableView/TableSectionBase.cs index b97dd8f698a4..560a8e9adb47 100644 --- a/src/Controls/src/Core/TableView/TableSectionBase.cs +++ b/src/Controls/src/Core/TableView/TableSectionBase.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls public abstract class TableSectionBase : BindableObject { /// Bindable property for . - public static readonly BindableProperty TitleProperty = BindableProperty.Create("Title", typeof(string), typeof(TableSectionBase), null); + public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(TableSectionBase), null); /// Bindable property for . public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(TableSectionBase), null); @@ -25,7 +25,7 @@ protected TableSectionBase() protected TableSectionBase(string title) { if (title == null) - throw new ArgumentNullException("title"); + throw new ArgumentNullException(nameof(title)); Title = title; } diff --git a/src/Controls/src/Core/TableView/TableView.cs b/src/Controls/src/Core/TableView/TableView.cs index 1cc56dc5ab10..0c895cec19b5 100644 --- a/src/Controls/src/Core/TableView/TableView.cs +++ b/src/Controls/src/Core/TableView/TableView.cs @@ -16,10 +16,10 @@ namespace Microsoft.Maui.Controls public class TableView : View, ITableViewController, IElementConfiguration, IVisualTreeElement { /// Bindable property for . - public static readonly BindableProperty RowHeightProperty = BindableProperty.Create("RowHeight", typeof(int), typeof(TableView), -1); + public static readonly BindableProperty RowHeightProperty = BindableProperty.Create(nameof(RowHeight), typeof(int), typeof(TableView), -1); /// Bindable property for . - public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create("HasUnevenRows", typeof(bool), typeof(TableView), false); + public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(TableView), false); readonly Lazy> _platformConfigurationRegistry; @@ -238,7 +238,7 @@ protected override void OnRowSelected(object item) internal static Tuple GetPath(Cell item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); return (Tuple)item.GetValue(PathProperty); } diff --git a/src/Controls/src/Core/TapGestureRecognizer.cs b/src/Controls/src/Core/TapGestureRecognizer.cs index f6c06f3ff3ec..ea0418b5e365 100644 --- a/src/Controls/src/Core/TapGestureRecognizer.cs +++ b/src/Controls/src/Core/TapGestureRecognizer.cs @@ -8,13 +8,13 @@ namespace Microsoft.Maui.Controls public sealed class TapGestureRecognizer : GestureRecognizer { /// Bindable property for . - public static readonly BindableProperty CommandProperty = BindableProperty.Create("Command", typeof(ICommand), typeof(TapGestureRecognizer), null); + public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(TapGestureRecognizer), null); /// Bindable property for . public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(TapGestureRecognizer), null); /// Bindable property for . - public static readonly BindableProperty NumberOfTapsRequiredProperty = BindableProperty.Create("NumberOfTapsRequired", typeof(int), typeof(TapGestureRecognizer), 1); + public static readonly BindableProperty NumberOfTapsRequiredProperty = BindableProperty.Create(nameof(NumberOfTapsRequired), typeof(int), typeof(TapGestureRecognizer), 1); /// Bindable property for . public static readonly BindableProperty ButtonsProperty = BindableProperty.Create(nameof(Buttons), typeof(ButtonsMask), typeof(TapGestureRecognizer), ButtonsMask.Primary); diff --git a/src/Controls/src/Core/TemplateBinding.cs b/src/Controls/src/Core/TemplateBinding.cs index 99c6bc51dc86..f913832206ba 100644 --- a/src/Controls/src/Core/TemplateBinding.cs +++ b/src/Controls/src/Core/TemplateBinding.cs @@ -24,9 +24,9 @@ public TemplateBinding() public TemplateBinding(string path, BindingMode mode = BindingMode.Default, IValueConverter converter = null, object converterParameter = null, string stringFormat = null) { if (path == null) - throw new ArgumentNullException("path"); + throw new ArgumentNullException(nameof(path)); if (string.IsNullOrWhiteSpace(path)) - throw new ArgumentException("path cannot be an empty string", "path"); + throw new ArgumentException("path cannot be an empty string", nameof(path)); AllowChaining = true; Path = path; diff --git a/src/Controls/src/Core/TemplateExtensions.cs b/src/Controls/src/Core/TemplateExtensions.cs index 01f45f532642..1e4b4d0e7c85 100644 --- a/src/Controls/src/Core/TemplateExtensions.cs +++ b/src/Controls/src/Core/TemplateExtensions.cs @@ -10,7 +10,7 @@ public static class TemplateExtensions public static void SetBinding(this DataTemplate self, BindableProperty targetProperty, string path) { if (self == null) - throw new ArgumentNullException("self"); + throw new ArgumentNullException(nameof(self)); self.SetBinding(targetProperty, new Binding(path)); } diff --git a/src/Controls/src/Core/TemplatedItemsList.cs b/src/Controls/src/Core/TemplatedItemsList.cs index 18b2b0a4e99f..967e6ae90643 100644 --- a/src/Controls/src/Core/TemplatedItemsList.cs +++ b/src/Controls/src/Core/TemplatedItemsList.cs @@ -20,14 +20,14 @@ public sealed class TemplatedItemsListBindable property for . - public static readonly BindableProperty NameProperty = BindableProperty.Create("Name", typeof(string), typeof(TemplatedItemsList), null); + public static readonly BindableProperty NameProperty = BindableProperty.Create(nameof(Name), typeof(string), typeof(TemplatedItemsList), null); /// Bindable property for . - public static readonly BindableProperty ShortNameProperty = BindableProperty.Create("ShortName", typeof(string), typeof(TemplatedItemsList), null); + public static readonly BindableProperty ShortNameProperty = BindableProperty.Create(nameof(ShortName), typeof(string), typeof(TemplatedItemsList), null); - static readonly BindablePropertyKey HeaderContentPropertyKey = BindableProperty.CreateReadOnly("HeaderContent", typeof(TItem), typeof(TemplatedItemsList), null); + static readonly BindablePropertyKey HeaderContentPropertyKey = BindableProperty.CreateReadOnly(nameof(HeaderContent), typeof(TItem), typeof(TemplatedItemsList), null); - internal static readonly BindablePropertyKey ListProxyPropertyKey = BindableProperty.CreateReadOnly("ListProxy", typeof(ListProxy), typeof(TemplatedItemsList), null, + internal static readonly BindablePropertyKey ListProxyPropertyKey = BindableProperty.CreateReadOnly(nameof(ListProxy), typeof(ListProxy), typeof(TemplatedItemsList), null, propertyChanged: OnListProxyChanged); static readonly BindableProperty GroupProperty = BindableProperty.Create("Group", typeof(TemplatedItemsList), typeof(TItem), null); @@ -53,11 +53,11 @@ public sealed class TemplatedItemsList parent, IEnumerable itemSource, TView itemsView, BindableProperty itemTemplateProperty, int windowSize = int.MaxValue) { if (itemsView == null) - throw new ArgumentNullException("itemsView"); + throw new ArgumentNullException(nameof(itemsView)); if (itemTemplateProperty == null) - throw new ArgumentNullException("itemTemplateProperty"); + throw new ArgumentNullException(nameof(itemTemplateProperty)); Parent = parent; @@ -360,7 +360,7 @@ public int GetDescendantCount() public int GetGlobalIndexForGroup(ITemplatedItemsList group) { if (group == null) - throw new ArgumentNullException("group"); + throw new ArgumentNullException(nameof(group)); int groupIndex = _groupedItems.Values.IndexOf(group); @@ -584,7 +584,7 @@ ITemplatedItemsList ITemplatedItemsList.GetGroup(int index) internal static TemplatedItemsList GetGroup(TItem item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); return (TemplatedItemsList)item.GetValue(GroupProperty); } @@ -592,7 +592,7 @@ internal static TemplatedItemsList GetGroup(TItem item) internal static int GetIndex(TItem item) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); return (int)item.GetValue(IndexProperty); } @@ -963,7 +963,7 @@ void OnItemTemplateChanged() static void OnListProxyChanged(BindableObject bindable, object oldValue, object newValue) { var til = (TemplatedItemsList)bindable; - til.OnPropertyChanged("ItemsSource"); + til.OnPropertyChanged(nameof(ItemsSource)); } void OnProxyCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -1137,7 +1137,7 @@ void OnShortNameBindingChanged() static void SetGroup(TItem item, TemplatedItemsList group) { if (item == null) - throw new ArgumentNullException("item"); + throw new ArgumentNullException(nameof(item)); item.SetValue(GroupProperty, group); } diff --git a/src/Controls/src/Core/Toolbar/ToolbarItem.cs b/src/Controls/src/Core/Toolbar/ToolbarItem.cs index 440cef1177b7..066f19ee1836 100644 --- a/src/Controls/src/Core/Toolbar/ToolbarItem.cs +++ b/src/Controls/src/Core/Toolbar/ToolbarItem.cs @@ -6,13 +6,13 @@ namespace Microsoft.Maui.Controls /// public class ToolbarItem : MenuItem { - static readonly BindableProperty OrderProperty = BindableProperty.Create("Order", typeof(ToolbarItemOrder), typeof(ToolbarItem), ToolbarItemOrder.Default, validateValue: (bo, o) => + static readonly BindableProperty OrderProperty = BindableProperty.Create(nameof(Order), typeof(ToolbarItemOrder), typeof(ToolbarItem), ToolbarItemOrder.Default, validateValue: (bo, o) => { var order = (ToolbarItemOrder)o; return order == ToolbarItemOrder.Default || order == ToolbarItemOrder.Primary || order == ToolbarItemOrder.Secondary; }); - static readonly BindableProperty PriorityProperty = BindableProperty.Create("Priority", typeof(int), typeof(ToolbarItem), 0); + static readonly BindableProperty PriorityProperty = BindableProperty.Create(nameof(Priority), typeof(int), typeof(ToolbarItem), 0); /// public ToolbarItem() @@ -23,7 +23,7 @@ public ToolbarItem() public ToolbarItem(string name, string icon, Action activated, ToolbarItemOrder order = ToolbarItemOrder.Default, int priority = 0) { if (activated == null) - throw new ArgumentNullException("activated"); + throw new ArgumentNullException(nameof(activated)); Text = name; IconImageSource = icon; diff --git a/src/Controls/src/Core/UrlWebViewSource.cs b/src/Controls/src/Core/UrlWebViewSource.cs index 91a3cbaf6b23..766ba88796d2 100644 --- a/src/Controls/src/Core/UrlWebViewSource.cs +++ b/src/Controls/src/Core/UrlWebViewSource.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Controls public class UrlWebViewSource : WebViewSource { /// Bindable property for . - public static readonly BindableProperty UrlProperty = BindableProperty.Create("Url", typeof(string), typeof(UrlWebViewSource), default(string), + public static readonly BindableProperty UrlProperty = BindableProperty.Create(nameof(Url), typeof(string), typeof(UrlWebViewSource), default(string), propertyChanged: (bindable, oldvalue, newvalue) => ((UrlWebViewSource)bindable).OnSourceChanged()); /// diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index 243e4a49eda8..e80440af8bb2 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -30,57 +30,57 @@ public partial class VisualElement : NavigableElement, IAnimatable, IVisualEleme /// Bindable property for . public static readonly BindableProperty InputTransparentProperty = BindableProperty.Create( - "InputTransparent", typeof(bool), typeof(VisualElement), default(bool), + nameof(InputTransparent), typeof(bool), typeof(VisualElement), default(bool), propertyChanged: OnInputTransparentPropertyChanged, coerceValue: CoerceInputTransparentProperty); bool _isEnabledExplicit = (bool)IsEnabledProperty.DefaultValue; /// Bindable property for . - public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create("IsEnabled", typeof(bool), + public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(VisualElement), true, propertyChanged: OnIsEnabledPropertyChanged, coerceValue: CoerceIsEnabledProperty); - static readonly BindablePropertyKey XPropertyKey = BindableProperty.CreateReadOnly("X", typeof(double), typeof(VisualElement), default(double)); + static readonly BindablePropertyKey XPropertyKey = BindableProperty.CreateReadOnly(nameof(X), typeof(double), typeof(VisualElement), default(double)); /// Bindable property for . public static readonly BindableProperty XProperty = XPropertyKey.BindableProperty; - static readonly BindablePropertyKey YPropertyKey = BindableProperty.CreateReadOnly("Y", typeof(double), typeof(VisualElement), default(double)); + static readonly BindablePropertyKey YPropertyKey = BindableProperty.CreateReadOnly(nameof(Y), typeof(double), typeof(VisualElement), default(double)); /// Bindable property for . public static readonly BindableProperty YProperty = YPropertyKey.BindableProperty; /// Bindable property for . - public static readonly BindableProperty AnchorXProperty = BindableProperty.Create("AnchorX", typeof(double), typeof(VisualElement), .5d); + public static readonly BindableProperty AnchorXProperty = BindableProperty.Create(nameof(AnchorX), typeof(double), typeof(VisualElement), .5d); /// Bindable property for . - public static readonly BindableProperty AnchorYProperty = BindableProperty.Create("AnchorY", typeof(double), typeof(VisualElement), .5d); + public static readonly BindableProperty AnchorYProperty = BindableProperty.Create(nameof(AnchorY), typeof(double), typeof(VisualElement), .5d); /// Bindable property for . - public static readonly BindableProperty TranslationXProperty = BindableProperty.Create("TranslationX", typeof(double), typeof(VisualElement), 0d); + public static readonly BindableProperty TranslationXProperty = BindableProperty.Create(nameof(TranslationX), typeof(double), typeof(VisualElement), 0d); /// Bindable property for . - public static readonly BindableProperty TranslationYProperty = BindableProperty.Create("TranslationY", typeof(double), typeof(VisualElement), 0d); + public static readonly BindableProperty TranslationYProperty = BindableProperty.Create(nameof(TranslationY), typeof(double), typeof(VisualElement), 0d); - static readonly BindablePropertyKey WidthPropertyKey = BindableProperty.CreateReadOnly("Width", typeof(double), typeof(VisualElement), -1d, + static readonly BindablePropertyKey WidthPropertyKey = BindableProperty.CreateReadOnly(nameof(Width), typeof(double), typeof(VisualElement), -1d, coerceValue: (bindable, value) => double.IsNaN((double)value) ? 0d : value); /// Bindable property for . public static readonly BindableProperty WidthProperty = WidthPropertyKey.BindableProperty; - static readonly BindablePropertyKey HeightPropertyKey = BindableProperty.CreateReadOnly("Height", typeof(double), typeof(VisualElement), -1d, + static readonly BindablePropertyKey HeightPropertyKey = BindableProperty.CreateReadOnly(nameof(Height), typeof(double), typeof(VisualElement), -1d, coerceValue: (bindable, value) => double.IsNaN((double)value) ? 0d : value); /// Bindable property for . public static readonly BindableProperty HeightProperty = HeightPropertyKey.BindableProperty; /// Bindable property for . - public static readonly BindableProperty RotationProperty = BindableProperty.Create("Rotation", typeof(double), typeof(VisualElement), default(double)); + public static readonly BindableProperty RotationProperty = BindableProperty.Create(nameof(Rotation), typeof(double), typeof(VisualElement), default(double)); /// Bindable property for . - public static readonly BindableProperty RotationXProperty = BindableProperty.Create("RotationX", typeof(double), typeof(VisualElement), default(double)); + public static readonly BindableProperty RotationXProperty = BindableProperty.Create(nameof(RotationX), typeof(double), typeof(VisualElement), default(double)); /// Bindable property for . - public static readonly BindableProperty RotationYProperty = BindableProperty.Create("RotationY", typeof(double), typeof(VisualElement), default(double)); + public static readonly BindableProperty RotationYProperty = BindableProperty.Create(nameof(RotationY), typeof(double), typeof(VisualElement), default(double)); /// Bindable property for . public static readonly BindableProperty ScaleProperty = BindableProperty.Create(nameof(Scale), typeof(double), typeof(VisualElement), 1d); @@ -266,11 +266,11 @@ static void OnTransformChanged(BindableObject bindable, object oldValue, object propertyChanged: (b, o, n) => { (((VisualElement)b).AnchorX, ((VisualElement)b).AnchorY) = (Point)n; }); /// Bindable property for . - public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create("IsVisible", typeof(bool), typeof(VisualElement), true, + public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(VisualElement), true, propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue)); /// Bindable property for . - public static readonly BindableProperty OpacityProperty = BindableProperty.Create("Opacity", typeof(double), typeof(VisualElement), 1d, coerceValue: (bindable, value) => ((double)value).Clamp(0, 1)); + public static readonly BindableProperty OpacityProperty = BindableProperty.Create(nameof(Opacity), typeof(double), typeof(VisualElement), 1d, coerceValue: (bindable, value) => ((double)value).Clamp(0, 1)); /// Bindable property for . public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(VisualElement), null); @@ -383,7 +383,7 @@ public override void Unsubscribe() } } - internal static readonly BindablePropertyKey BehaviorsPropertyKey = BindableProperty.CreateReadOnly("Behaviors", typeof(IList), typeof(VisualElement), default(IList), + internal static readonly BindablePropertyKey BehaviorsPropertyKey = BindableProperty.CreateReadOnly(nameof(Behaviors), typeof(IList), typeof(VisualElement), default(IList), defaultValueCreator: bindable => { var collection = new AttachedCollection(); @@ -394,7 +394,7 @@ public override void Unsubscribe() /// Bindable property for . public static readonly BindableProperty BehaviorsProperty = BehaviorsPropertyKey.BindableProperty; - internal static readonly BindablePropertyKey TriggersPropertyKey = BindableProperty.CreateReadOnly("Triggers", typeof(IList), typeof(VisualElement), default(IList), + internal static readonly BindablePropertyKey TriggersPropertyKey = BindableProperty.CreateReadOnly(nameof(Triggers), typeof(IList), typeof(VisualElement), default(IList), defaultValueCreator: bindable => { var collection = new AttachedCollection(); @@ -428,7 +428,7 @@ public override void Unsubscribe() /// Bindable property for . /// For internal use only. This API can be changed or removed without notice at any time. [EditorBrowsable(EditorBrowsableState.Never)] - public static readonly BindablePropertyKey IsFocusedPropertyKey = BindableProperty.CreateReadOnly("IsFocused", + public static readonly BindablePropertyKey IsFocusedPropertyKey = BindableProperty.CreateReadOnly(nameof(IsFocused), typeof(bool), typeof(VisualElement), default(bool), propertyChanged: OnIsFocusedPropertyChanged); /// Bindable property for . diff --git a/src/Controls/src/Core/WebView/WebView.cs b/src/Controls/src/Core/WebView/WebView.cs index 90adebd7a3a7..bce0f87038d5 100644 --- a/src/Controls/src/Core/WebView/WebView.cs +++ b/src/Controls/src/Core/WebView/WebView.cs @@ -14,7 +14,7 @@ namespace Microsoft.Maui.Controls public partial class WebView : View, IWebViewController, IElementConfiguration, IWebView { /// Bindable property for . - public static readonly BindableProperty SourceProperty = BindableProperty.Create("Source", typeof(WebViewSource), typeof(WebView), default(WebViewSource), + public static readonly BindableProperty SourceProperty = BindableProperty.Create(nameof(Source), typeof(WebViewSource), typeof(WebView), default(WebViewSource), propertyChanging: (bindable, oldvalue, newvalue) => { var source = oldvalue as WebViewSource; @@ -31,12 +31,12 @@ public partial class WebView : View, IWebViewController, IElementConfigurationBindable property for . public static readonly BindableProperty CanGoBackProperty = CanGoBackPropertyKey.BindableProperty; - static readonly BindablePropertyKey CanGoForwardPropertyKey = BindableProperty.CreateReadOnly("CanGoForward", typeof(bool), typeof(WebView), false); + static readonly BindablePropertyKey CanGoForwardPropertyKey = BindableProperty.CreateReadOnly(nameof(CanGoForward), typeof(bool), typeof(WebView), false); /// Bindable property for . public static readonly BindableProperty CanGoForwardProperty = CanGoForwardPropertyKey.BindableProperty;