diff --git a/src/Caliburn.Micro.Avalonia.Tests/ScopeNamingRouteTests.cs b/src/Caliburn.Micro.Avalonia.Tests/ScopeNamingRouteTests.cs index 96d5dbfb9..a27ca759c 100644 --- a/src/Caliburn.Micro.Avalonia.Tests/ScopeNamingRouteTests.cs +++ b/src/Caliburn.Micro.Avalonia.Tests/ScopeNamingRouteTests.cs @@ -25,8 +25,7 @@ public void CorrectlyGetsAddedHop() var d1 = new AvaloniaObject(); var d2 = new AvaloniaObject(); route.AddHop(d1, d2); - AvaloniaObject target; - var result = route.TryGetHop(d1, out target); + var result = route.TryGetHop(d1, out AvaloniaObject target); Assert.True(result); Assert.Same(d2, target); } @@ -52,9 +51,8 @@ public void GetsAllHopsAdded() }; var source = d1; - AvaloniaObject target; - while (route.TryGetHop(source, out target)) + while (route.TryGetHop(source, out AvaloniaObject target)) { all.Remove(target); source = target; diff --git a/src/Caliburn.Micro.Avalonia.Tests/ViewModelLocatorTests.cs b/src/Caliburn.Micro.Avalonia.Tests/ViewModelLocatorTests.cs index 8d5c462a9..f8a9f8ed8 100644 --- a/src/Caliburn.Micro.Avalonia.Tests/ViewModelLocatorTests.cs +++ b/src/Caliburn.Micro.Avalonia.Tests/ViewModelLocatorTests.cs @@ -56,7 +56,7 @@ public void ConfigureTypeMappingsShouldThrowWhenDefaultSubNamespaceForViewsIsNul [Fact] - public void COnfigureTypeMappingsWithDefaultValuesShouldNotThrow() + public void ConfigureTypeMappingsWithDefaultValuesShouldNotThrow() { var typeMappingConfiguration = new TypeMappingConfiguration(); diff --git a/src/Caliburn.Micro.Core.Tests/IoCTests.cs b/src/Caliburn.Micro.Core.Tests/IoCTests.cs index a3c5b1160..fbf00de19 100644 --- a/src/Caliburn.Micro.Core.Tests/IoCTests.cs +++ b/src/Caliburn.Micro.Core.Tests/IoCTests.cs @@ -61,7 +61,7 @@ public void A_not_initialized_GetInstance_throws_an_InvalidOperationException() } [Fact] - public void A_null_GetInstance_throws_a_NullRefrenceException() + public void A_null_GetInstance_throws_a_NullReferenceException() { using (IoCReset.Create()) { diff --git a/src/Caliburn.Micro.Core.Tests/ScreenExtentionTests.cs b/src/Caliburn.Micro.Core.Tests/ScreenExtentionTests.cs index 184b34bda..13e30dca4 100644 --- a/src/Caliburn.Micro.Core.Tests/ScreenExtentionTests.cs +++ b/src/Caliburn.Micro.Core.Tests/ScreenExtentionTests.cs @@ -12,20 +12,10 @@ public async Task Screen_ConductWithTests() { var root = new Screen(); - var child1 = new StateScreen - { - DisplayName = "screen1" - }; + var child1 = new StateScreen { DisplayName = "screen1" }; // simulate a long deactivation process - var child2 = new StateScreen(TimeSpan.FromSeconds(3)) - { - DisplayName = "screen2" - }; - - var child3 = new StateScreen() - { - DisplayName = "screen3" - }; + var child2 = new StateScreen(TimeSpan.FromSeconds(3)) { DisplayName = "screen2" }; + var child3 = new StateScreen() { DisplayName = "screen3" }; child1.ConductWith(root); child2.ConductWith(root); @@ -49,20 +39,13 @@ public async Task Conductor_ConductWithTests() { var root = new Conductor.Collection.AllActive(); - var child1 = new StateScreen - { - DisplayName = "screen1" - }; + var child1 = new StateScreen { DisplayName = "screen1" }; var child2 = new StateScreen(TimeSpan.FromSeconds(3)) { DisplayName = "screen2", IsClosable = false, }; - - var child3 = new StateScreen() - { - DisplayName = "screen3" - }; + var child3 = new StateScreen() { DisplayName = "screen3" }; root.Items.Add(child1); root.Items.Add(child2); @@ -81,8 +64,10 @@ public async Task Conductor_ConductWithTests() Assert.True(child3.IsClosed, "child 3 should be closed"); } - class StateScreen : Screen + private sealed class StateScreen : Screen { + private readonly TimeSpan? deactivationDelay; + public StateScreen() { } @@ -93,7 +78,9 @@ public StateScreen(TimeSpan? deactivationDelay) } public bool WasActivated { get; private set; } + public bool IsClosed { get; private set; } + public bool IsClosable { get; set; } public override Task CanCloseAsync(CancellationToken cancellationToken = default) @@ -129,7 +116,7 @@ protected override async Task OnActivatedAsync(CancellationToken cancellationTok IsClosable = false; } - protected override async Task OnDeactivateAsync(bool close, CancellationToken cancellationToken = default(CancellationToken)) + protected override async Task OnDeactivateAsync(bool close, CancellationToken cancellationToken = default) { await base.OnDeactivateAsync(close, cancellationToken); @@ -140,8 +127,6 @@ protected override async Task OnActivatedAsync(CancellationToken cancellationTok IsClosed = close; } - - private readonly TimeSpan? deactivationDelay; } } } diff --git a/src/Caliburn.Micro.Core.Tests/SimpleContainerTests.cs b/src/Caliburn.Micro.Core.Tests/SimpleContainerTests.cs index e6c1381a6..db192ce61 100644 --- a/src/Caliburn.Micro.Core.Tests/SimpleContainerTests.cs +++ b/src/Caliburn.Micro.Core.Tests/SimpleContainerTests.cs @@ -89,7 +89,7 @@ public void Null_is_returned_when_no_instance_is_found() public class SimpleContainerRegisteringInstances { [Fact] - public void Instances_registed_Singleton_return_the_same_instance_for_each_call() + public void Instances_registered_Singleton_return_the_same_instance_for_each_call() { var container = new SimpleContainer(); container.Singleton(); @@ -146,7 +146,7 @@ public void Container_Finds_Single_Constructor() public class SingleNonEmptyConstructorType { - public SingleNonEmptyConstructorType(SimpleContainer_Find_Constructor.SingleEmptyConstructorType type) + public SingleNonEmptyConstructorType(SingleEmptyConstructorType type) { } } @@ -165,18 +165,18 @@ public class SingleIntConstructor public SingleIntConstructor(int x) { - this.Value = x; + Value = x; } } [Fact] public void Container_SingleIntConstructor() { - var container = new SimpleContainer(); - container.Singleton(); - container.RegisterInstance(typeof(int), "x", 4); - var inst = (SingleIntConstructor)container.GetInstance(typeof(SingleIntConstructor), null); - Assert.Equal(4, inst.Value); + var sut = new SimpleContainer(); + sut.Singleton(); + sut.RegisterInstance(typeof(int), "x", 4); + var result = (SingleIntConstructor)sut.GetInstance(typeof(SingleIntConstructor), null); + Assert.Equal(4, result.Value); } public class TwoConstructors @@ -185,7 +185,7 @@ public class TwoConstructors public TwoConstructors() { - this.Value = 42; + Value = 42; } public TwoConstructors(int value) @@ -197,20 +197,20 @@ public TwoConstructors(int value) [Fact] public void Container_ChooseConstructorWithRegisteredParameter() { - var container = new SimpleContainer(); - container.Singleton(); - container.RegisterInstance(typeof(int), null, 23); - var inst = (TwoConstructors)container.GetInstance(typeof(TwoConstructors), null); - Assert.Equal(23, inst.Value); + var sut = new SimpleContainer(); + sut.Singleton(); + sut.RegisterInstance(typeof(int), null, 23); + var result = (TwoConstructors)sut.GetInstance(typeof(TwoConstructors), null); + Assert.Equal(23, result.Value); } [Fact] public void Container_ChooseEmptyConstructorWithoutRegisteredParameter() { - var container = new SimpleContainer(); - container.Singleton(); - var inst = (TwoConstructors)container.GetInstance(typeof(TwoConstructors), null); - Assert.Equal(42, inst.Value); + var sut = new SimpleContainer(); + sut.Singleton(); + var result = (TwoConstructors)sut.GetInstance(typeof(TwoConstructors), null); + Assert.Equal(42, result.Value); } } diff --git a/src/Caliburn.Micro.Core/AsyncEventHandler.cs b/src/Caliburn.Micro.Core/AsyncEventHandler.cs index 9e76af372..8a3d9bad9 100644 --- a/src/Caliburn.Micro.Core/AsyncEventHandler.cs +++ b/src/Caliburn.Micro.Core/AsyncEventHandler.cs @@ -10,8 +10,6 @@ namespace Caliburn.Micro /// The source of the event. /// An object that contains the event data. /// A task that represents the asynchronous operation. - public delegate Task AsyncEventHandler( - object sender, - TEventArgs e) + public delegate Task AsyncEventHandler(object sender, TEventArgs e) where TEventArgs : EventArgs; } diff --git a/src/Caliburn.Micro.Core/BindableCollection.cs b/src/Caliburn.Micro.Core/BindableCollection.cs index 0a43719fb..232dcb8ff 100644 --- a/src/Caliburn.Micro.Core/BindableCollection.cs +++ b/src/Caliburn.Micro.Core/BindableCollection.cs @@ -43,14 +43,7 @@ public virtual void NotifyOfPropertyChange(string propertyName) { if (IsNotifying) { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => OnPropertyChanged(new PropertyChangedEventArgs(propertyName))); - } - else - { - OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); - } + Execute.DispatchIfRequired(() => OnPropertyChanged(new PropertyChangedEventArgs(propertyName))); } } @@ -59,21 +52,12 @@ public virtual void NotifyOfPropertyChange(string propertyName) /// public void Refresh() { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => - { - OnPropertyChanged(new PropertyChangedEventArgs("Count")); - OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); - OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - }); - } - else + Execute.DispatchIfRequired(() => { OnPropertyChanged(new PropertyChangedEventArgs("Count")); OnPropertyChanged(new PropertyChangedEventArgs("Item[]")); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - } + }); } /// @@ -83,14 +67,7 @@ public void Refresh() /// The item to be inserted. protected override sealed void InsertItem(int index, T item) { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => InsertItemBase(index, item)); - } - else - { - InsertItemBase(index, item); - } + Execute.DispatchIfRequired(() => InsertItemBase(index, item)); } /// @@ -113,14 +90,7 @@ protected virtual void InsertItemBase(int index, T item) /// The item to set. protected override sealed void SetItem(int index, T item) { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => SetItemBase(index, item)); - } - else - { - SetItemBase(index, item); - } + Execute.DispatchIfRequired(() => SetItemBase(index, item)); } /// @@ -142,14 +112,7 @@ protected virtual void SetItemBase(int index, T item) /// The position used to identify the item to remove. protected override sealed void RemoveItem(int index) { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => RemoveItemBase(index)); - } - else - { - RemoveItemBase(index); - } + Execute.DispatchIfRequired(() => RemoveItemBase(index)); } /// @@ -223,6 +186,7 @@ void AddRange() InsertItemBase(index, item); index++; } + IsNotifying = previousNotificationSetting; OnPropertyChanged(new PropertyChangedEventArgs("Count")); @@ -230,14 +194,7 @@ void AddRange() OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(AddRange); - } - else - { - AddRange(); - } + Execute.DispatchIfRequired(AddRange); } /// @@ -258,6 +215,7 @@ void RemoveRange() RemoveItemBase(index); } } + IsNotifying = previousNotificationSetting; OnPropertyChanged(new PropertyChangedEventArgs("Count")); @@ -265,21 +223,14 @@ void RemoveRange() OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); } - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(RemoveRange); - } - else - { - RemoveRange(); - } + Execute.DispatchIfRequired(RemoveRange); } /// /// Executes the given action on the UI thread /// - /// An extension point for subclasses to customise how property change notifications are handled. + /// An extension point for subclasses to customize how property change notifications are handled. /// - protected virtual void OnUIThread(System.Action action) => action.OnUIThread(); + protected virtual void OnUIThread(Action action) => action.OnUIThread(); } } diff --git a/src/Caliburn.Micro.Core/Conductor.cs b/src/Caliburn.Micro.Core/Conductor.cs index f26295186..55a0654d5 100644 --- a/src/Caliburn.Micro.Core/Conductor.cs +++ b/src/Caliburn.Micro.Core/Conductor.cs @@ -52,7 +52,7 @@ public override async Task DeactivateItemAsync(T item, bool close, CancellationT if (closeResult.CloseCanOccur) { - await ChangeActiveItemAsync(default(T), close, cancellationToken); + await ChangeActiveItemAsync(default, close, cancellationToken); } } diff --git a/src/Caliburn.Micro.Core/ConductorBase.cs b/src/Caliburn.Micro.Core/ConductorBase.cs index ae9d0f13c..840c50e17 100644 --- a/src/Caliburn.Micro.Core/ConductorBase.cs +++ b/src/Caliburn.Micro.Core/ConductorBase.cs @@ -20,7 +20,7 @@ public abstract class ConductorBase : Screen, IConductor, IParent where T /// The close strategy. public ICloseStrategy CloseStrategy { - get => _closeStrategy ?? (_closeStrategy = new DefaultCloseStrategy()); + get => _closeStrategy ??= new DefaultCloseStrategy(); set => _closeStrategy = value; } @@ -91,7 +91,7 @@ protected virtual void OnActivationProcessed(T item, bool success) /// The item to be activated. protected virtual T EnsureItem(T newItem) { - if (newItem is IChild node && !object.ReferenceEquals(node.Parent, this)) + if (newItem is IChild node && !ReferenceEquals(node.Parent, this)) node.Parent = this; return newItem; diff --git a/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs b/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs index 7fc51b706..53a2bf4da 100644 --- a/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs +++ b/src/Caliburn.Micro.Core/ConductorBaseWithActiveItem.cs @@ -7,7 +7,8 @@ namespace Caliburn.Micro /// A base class for various implementations of that maintain an active item. /// /// The type that is being conducted. - public abstract class ConductorBaseWithActiveItem : ConductorBase, IConductActiveItem where T : class + public abstract class ConductorBaseWithActiveItem : ConductorBase, IConductActiveItem + where T : class { private T _activeItem; diff --git a/src/Caliburn.Micro.Core/ConductorExtensions.cs b/src/Caliburn.Micro.Core/ConductorExtensions.cs index 283df14a8..91e151d41 100644 --- a/src/Caliburn.Micro.Core/ConductorExtensions.cs +++ b/src/Caliburn.Micro.Core/ConductorExtensions.cs @@ -1,5 +1,4 @@ -using System.Threading; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Caliburn.Micro { diff --git a/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs b/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs index dd3173ec0..e49b9025f 100644 --- a/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs +++ b/src/Caliburn.Micro.Core/ConductorWithCollectionOneActive.cs @@ -136,7 +136,7 @@ protected virtual T DetermineNextItemToActivate(IList list, int lastIndex) if (toRemoveAt > -1 && toRemoveAt < list.Count - 1) return list[toRemoveAt]; - return default(T); + return default; } /// diff --git a/src/Caliburn.Micro.Core/ContainerExtensions.cs b/src/Caliburn.Micro.Core/ContainerExtensions.cs index bd8140d15..31b3dc86a 100644 --- a/src/Caliburn.Micro.Core/ContainerExtensions.cs +++ b/src/Caliburn.Micro.Core/ContainerExtensions.cs @@ -99,13 +99,9 @@ public static SimpleContainer Handler(this SimpleContainer container, /// The assembly. /// The type filter. /// The container. - public static SimpleContainer AllTypesOf(this SimpleContainer container, Assembly assembly, - Func filter = null) + public static SimpleContainer AllTypesOf(this SimpleContainer container, Assembly assembly, Func filter = null) { - if (filter == null) - { - filter = type => true; - } + filter ??= type => true; var serviceType = typeof(TService); var types = from type in assembly.DefinedTypes @@ -153,7 +149,7 @@ public static IEnumerable GetAllInstances(this SimpleContain /// The service type. /// The container. /// The key. - /// True if a handler is registere; false otherwise. + /// True if a handler is registered; false otherwise. public static bool HasHandler(this SimpleContainer container, string key = null) { return container.HasHandler(typeof(TService), key); diff --git a/src/Caliburn.Micro.Core/ContinueResultDecorator.cs b/src/Caliburn.Micro.Core/ContinueResultDecorator.cs index 4d6233123..444c976a6 100644 --- a/src/Caliburn.Micro.Core/ContinueResultDecorator.cs +++ b/src/Caliburn.Micro.Core/ContinueResultDecorator.cs @@ -18,12 +18,7 @@ public class ContinueResultDecorator : ResultDecoratorBase public ContinueResultDecorator(IResult result, Func coroutine) : base(result) { - if (coroutine == null) - { - throw new ArgumentNullException("coroutine"); - } - - this.coroutine = coroutine; + this.coroutine = coroutine ?? throw new ArgumentNullException(nameof(coroutine)); } /// diff --git a/src/Caliburn.Micro.Core/Coroutine.cs b/src/Caliburn.Micro.Core/Coroutine.cs index 2b357960c..ec555da0c 100644 --- a/src/Caliburn.Micro.Core/Coroutine.cs +++ b/src/Caliburn.Micro.Core/Coroutine.cs @@ -69,13 +69,13 @@ public static Task ExecuteAsync(IEnumerator coroutine, CoroutineExecuti private static void ExecuteOnCompleted(IResult result, EventHandler handler) { - EventHandler onCompledted = null; - onCompledted = (s, e) => + void OnCompleted(object s, ResultCompletionEventArgs e) { - result.Completed -= onCompledted; + result.Completed -= OnCompleted; handler(s, e); - }; - result.Completed += onCompledted; + } + + result.Completed += OnCompleted; } /// diff --git a/src/Caliburn.Micro.Core/DebugLog.cs b/src/Caliburn.Micro.Core/DebugLog.cs index 1cb32c9dc..eb9a5762d 100644 --- a/src/Caliburn.Micro.Core/DebugLog.cs +++ b/src/Caliburn.Micro.Core/DebugLog.cs @@ -6,7 +6,7 @@ namespace Caliburn.Micro { /// - /// A simple logger thats logs everything to the debugger. + /// A simple logger that logs everything to the debugger. /// public class DebugLog : ILog { diff --git a/src/Caliburn.Micro.Core/DefaultCloseStrategy.cs b/src/Caliburn.Micro.Core/DefaultCloseStrategy.cs index e5d7263f9..f457cfae2 100644 --- a/src/Caliburn.Micro.Core/DefaultCloseStrategy.cs +++ b/src/Caliburn.Micro.Core/DefaultCloseStrategy.cs @@ -46,7 +46,7 @@ public async Task> ExecuteAsync(IEnumerable toClose, Cancella } } - if (!this.closeConductedItemsWhenConductorCannotClose && !closeCanOccur) + if (!closeConductedItemsWhenConductorCannotClose && !closeCanOccur) { closeable.Clear(); } diff --git a/src/Caliburn.Micro.Core/DefaultPlatformProvider.cs b/src/Caliburn.Micro.Core/DefaultPlatformProvider.cs index de6d215a8..b021de0e3 100644 --- a/src/Caliburn.Micro.Core/DefaultPlatformProvider.cs +++ b/src/Caliburn.Micro.Core/DefaultPlatformProvider.cs @@ -47,7 +47,7 @@ public virtual void OnUIThread(Action action) } /// - /// Whether or not classes should execute property change notications on the UI thread. + /// Whether or not classes should execute property change notifications on the UI thread. /// public virtual bool PropertyChangeNotificationsOnUIThread => true; diff --git a/src/Caliburn.Micro.Core/DelegateResult.cs b/src/Caliburn.Micro.Core/DelegateResult.cs index cc7781995..d4ad2c1ce 100644 --- a/src/Caliburn.Micro.Core/DelegateResult.cs +++ b/src/Caliburn.Micro.Core/DelegateResult.cs @@ -3,7 +3,7 @@ namespace Caliburn.Micro { /// - /// A result that executes an . + /// A result that executes an . /// public class DelegateResult : IResult { @@ -45,7 +45,7 @@ public void Execute(CoroutineExecutionContext context) } /// - /// A result that executes a + /// A result that executes a /// /// The type of the result. public class DelegateResult : IResult diff --git a/src/Caliburn.Micro.Core/EventAggregator.cs b/src/Caliburn.Micro.Core/EventAggregator.cs index a6342e00a..91479adcb 100644 --- a/src/Caliburn.Micro.Core/EventAggregator.cs +++ b/src/Caliburn.Micro.Core/EventAggregator.cs @@ -120,9 +120,6 @@ public Handler(object handler, Func, Task> marshal) _marshal = marshal; _reference = new WeakReference(handler); - //var interfaces = handler.GetType().GetTypeInfo().ImplementedInterfaces - // .Where(x => typeof(IHandle).GetTypeInfo().IsAssignableFrom(x.GetTypeInfo()) && x.GetTypeInfo().IsGenericType); - var interfaces = handler.GetType().GetTypeInfo().ImplementedInterfaces .Where(x => x.GetTypeInfo().IsGenericType && x.GetGenericTypeDefinition() == typeof(IHandle<>)); @@ -142,7 +139,7 @@ public Handler(object handler, Func, Task> marshal) public bool Matches(object instance) { - return object.ReferenceEquals(_reference.Target, instance); + return ReferenceEquals(_reference.Target, instance); } public Task Handle(Type messageType, object message, CancellationToken cancellationToken) diff --git a/src/Caliburn.Micro.Core/EventAggregatorExtensions.cs b/src/Caliburn.Micro.Core/EventAggregatorExtensions.cs index f920275ed..68cd99846 100644 --- a/src/Caliburn.Micro.Core/EventAggregatorExtensions.cs +++ b/src/Caliburn.Micro.Core/EventAggregatorExtensions.cs @@ -79,7 +79,7 @@ public static void SubscribeOnUIThread(this IEventAggregator eventAggregator, ob } /// - /// Publishes a message on the current thread (synchrone). + /// Publishes a message on the current thread (Synchronous). /// /// The event aggregator. /// The message instance. @@ -91,7 +91,7 @@ public static Task PublishOnCurrentThreadAsync(this IEventAggregator eventAggreg } /// - /// Publishes a message on the current thread (synchrone). + /// Publishes a message on the current thread (Synchronous). /// /// The event aggregator. /// The message instance. diff --git a/src/Caliburn.Micro.Core/Execute.cs b/src/Caliburn.Micro.Core/Execute.cs index 8aec3a143..7fadd1453 100644 --- a/src/Caliburn.Micro.Core/Execute.cs +++ b/src/Caliburn.Micro.Core/Execute.cs @@ -45,5 +45,21 @@ public static void OnUIThread(this Action action) { PlatformProvider.Current.OnUIThread(action); } + + /// + /// Executes the action on the UI thread if required, otherwise executes it immediately. + /// + /// The action to execute. + public static void DispatchIfRequired(this Action action) + { + if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) + { + OnUIThread(action); + } + else + { + action(); + } + } } } diff --git a/src/Caliburn.Micro.Core/ExpressionExtensions.cs b/src/Caliburn.Micro.Core/ExpressionExtensions.cs index 047202d9e..4573ef65d 100644 --- a/src/Caliburn.Micro.Core/ExpressionExtensions.cs +++ b/src/Caliburn.Micro.Core/ExpressionExtensions.cs @@ -17,16 +17,10 @@ public static MemberInfo GetMemberInfo(this Expression expression) { var lambda = (LambdaExpression)expression; - MemberExpression memberExpression; - if (lambda.Body is UnaryExpression) - { - var unaryExpression = (UnaryExpression)lambda.Body; - memberExpression = (MemberExpression)unaryExpression.Operand; - } - else - { - memberExpression = (MemberExpression)lambda.Body; - } + MemberExpression memberExpression = (MemberExpression)( + lambda.Body is UnaryExpression unaryExpression + ? unaryExpression.Operand + : lambda.Body); return memberExpression.Member; } diff --git a/src/Caliburn.Micro.Core/IActivate.cs b/src/Caliburn.Micro.Core/IActivate.cs index d59318d97..deaf5edae 100644 --- a/src/Caliburn.Micro.Core/IActivate.cs +++ b/src/Caliburn.Micro.Core/IActivate.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading; +using System.Threading; using System.Threading.Tasks; namespace Caliburn.Micro diff --git a/src/Caliburn.Micro.Core/ICloseResult.cs b/src/Caliburn.Micro.Core/ICloseResult.cs index c165b4a81..37fcfe2e0 100644 --- a/src/Caliburn.Micro.Core/ICloseResult.cs +++ b/src/Caliburn.Micro.Core/ICloseResult.cs @@ -8,7 +8,7 @@ namespace Caliburn.Micro public interface ICloseResult { /// - /// Indicates which children shbould close if the parent cannot. + /// Indicates which children should close if the parent cannot. /// IEnumerable Children { get; } diff --git a/src/Caliburn.Micro.Core/ICloseStrategy.cs b/src/Caliburn.Micro.Core/ICloseStrategy.cs index 4d365d0ad..8d2b802d1 100644 --- a/src/Caliburn.Micro.Core/ICloseStrategy.cs +++ b/src/Caliburn.Micro.Core/ICloseStrategy.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; diff --git a/src/Caliburn.Micro.Core/IConductor.cs b/src/Caliburn.Micro.Core/IConductor.cs index ce0c7666e..737ec1eb3 100644 --- a/src/Caliburn.Micro.Core/IConductor.cs +++ b/src/Caliburn.Micro.Core/IConductor.cs @@ -7,7 +7,7 @@ namespace Caliburn.Micro /// /// Denotes an instance which conducts other objects by managing an ActiveItem and maintaining a strict lifecycle. /// - /// Conducted instances can optin to the lifecycle by impelenting any of the follosing , , . + /// Conducted instances can opt-in to the lifecycle by implementing any of the following , , . public interface IConductor : IParent, INotifyPropertyChangedEx { /// diff --git a/src/Caliburn.Micro.Core/IHandle.cs b/src/Caliburn.Micro.Core/IHandle.cs index 5c3f32399..c833c30a7 100644 --- a/src/Caliburn.Micro.Core/IHandle.cs +++ b/src/Caliburn.Micro.Core/IHandle.cs @@ -7,8 +7,7 @@ namespace Caliburn.Micro /// Denotes a class which can handle a particular type of message. /// /// The type of message to handle. - // ReSharper disable once TypeParameterCanBeVariant - public interface IHandle + public interface IHandle { /// /// Handles the message. @@ -17,6 +16,5 @@ public interface IHandle /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// A task that represents the asynchronous coroutine. Task HandleAsync(TMessage message, CancellationToken cancellationToken); - } } diff --git a/src/Caliburn.Micro.Core/IPlatformProvider.cs b/src/Caliburn.Micro.Core/IPlatformProvider.cs index e314efc9e..794aa1d31 100644 --- a/src/Caliburn.Micro.Core/IPlatformProvider.cs +++ b/src/Caliburn.Micro.Core/IPlatformProvider.cs @@ -16,7 +16,7 @@ public interface IPlatformProvider bool InDesignMode { get; } /// - /// Whether or not classes should execute property change notications on the UI thread. + /// Whether or not classes should execute property change notifications on the UI thread. /// bool PropertyChangeNotificationsOnUIThread { get; } diff --git a/src/Caliburn.Micro.Core/LogManager.cs b/src/Caliburn.Micro.Core/LogManager.cs index 6d1dab146..d1512a566 100644 --- a/src/Caliburn.Micro.Core/LogManager.cs +++ b/src/Caliburn.Micro.Core/LogManager.cs @@ -14,11 +14,16 @@ public static class LogManager /// public static Func GetLog = type => NullLogInstance; - private class NullLog : ILog + private sealed class NullLog : ILog { - public void Info(string format, params object[] args) { } - public void Warn(string format, params object[] args) { } - public void Error(Exception exception) { } + public void Info(string format, params object[] args) { + } + + public void Warn(string format, params object[] args) { + } + + public void Error(Exception exception) { + } } } } diff --git a/src/Caliburn.Micro.Core/PropertyChangedBase.cs b/src/Caliburn.Micro.Core/PropertyChangedBase.cs index 78d4c530c..7b9712547 100644 --- a/src/Caliburn.Micro.Core/PropertyChangedBase.cs +++ b/src/Caliburn.Micro.Core/PropertyChangedBase.cs @@ -47,14 +47,7 @@ public virtual void NotifyOfPropertyChange([System.Runtime.CompilerServices.Call { if (IsNotifying && PropertyChanged != null) { - if (PlatformProvider.Current.PropertyChangeNotificationsOnUIThread) - { - OnUIThread(() => OnPropertyChanged(new PropertyChangedEventArgs(propertyName))); - } - else - { - OnPropertyChanged(new PropertyChangedEventArgs(propertyName)); - } + Execute.DispatchIfRequired(() => OnPropertyChanged(new PropertyChangedEventArgs(propertyName))); } } @@ -81,7 +74,7 @@ protected void OnPropertyChanged(PropertyChangedEventArgs e) /// /// Executes the given action on the UI thread /// - /// An extension point for subclasses to customise how property change notifications are handled. + /// An extension point for subclasses to customize how property change notifications are handled. /// protected virtual void OnUIThread(System.Action action) => action.OnUIThread(); diff --git a/src/Caliburn.Micro.Core/RescueResultDecorator.cs b/src/Caliburn.Micro.Core/RescueResultDecorator.cs index 6ba3a2fcb..8fb40fdcf 100644 --- a/src/Caliburn.Micro.Core/RescueResultDecorator.cs +++ b/src/Caliburn.Micro.Core/RescueResultDecorator.cs @@ -6,7 +6,8 @@ namespace Caliburn.Micro /// A result decorator which rescues errors from the decorated result by executing a rescue coroutine. /// /// The type of the exception we want to perform the rescue on - public class RescueResultDecorator : ResultDecoratorBase where TException : Exception + public class RescueResultDecorator : ResultDecoratorBase + where TException : Exception { private static readonly ILog Log = LogManager.GetLog(typeof(RescueResultDecorator<>)); private readonly bool cancelResult; @@ -32,8 +33,7 @@ public RescueResultDecorator(IResult result, Func coroutine /// The instance containing the event data. protected override void OnInnerResultCompleted(CoroutineExecutionContext methodContext, IResult methodInnerResult, ResultCompletionEventArgs args) { - var error = args.Error as TException; - if (error == null) + if (args.Error is not TException error) { OnCompleted(args); } diff --git a/src/Caliburn.Micro.Core/ResultExtensions.cs b/src/Caliburn.Micro.Core/ResultExtensions.cs index 4c1c05f57..26e78dc69 100644 --- a/src/Caliburn.Micro.Core/ResultExtensions.cs +++ b/src/Caliburn.Micro.Core/ResultExtensions.cs @@ -36,8 +36,7 @@ public static IResult OverrideCancel(this IResult result) /// The rescue coroutine. /// Set to true to cancel the result after executing rescue. /// - public static IResult Rescue(this IResult result, Func rescue, - bool cancelResult = true) + public static IResult Rescue(this IResult result, Func rescue, bool cancelResult = true) where TException : Exception { return new RescueResultDecorator(result, rescue, cancelResult); @@ -50,8 +49,7 @@ public static IResult Rescue(this IResult result, FuncThe rescue coroutine. /// Set to true to cancel the result after executing rescue. /// - public static IResult Rescue(this IResult result, Func rescue, - bool cancelResult = true) + public static IResult Rescue(this IResult result, Func rescue, bool cancelResult = true) { return Rescue(result, rescue, cancelResult); } diff --git a/src/Caliburn.Micro.Core/Screen.cs b/src/Caliburn.Micro.Core/Screen.cs index 80c68f65f..707a89377 100644 --- a/src/Caliburn.Micro.Core/Screen.cs +++ b/src/Caliburn.Micro.Core/Screen.cs @@ -95,7 +95,7 @@ private set async Task IActivate.ActivateAsync(CancellationToken cancellationToken) { - Log.Info("Activating async {0}.", this.DisplayName); + Log.Info("Activating async {0}.", DisplayName); if (IsActive) return; @@ -125,7 +125,7 @@ async Task IActivate.ActivateAsync(CancellationToken cancellationToken) async Task IDeactivate.DeactivateAsync(bool close, CancellationToken cancellationToken) { - Log.Info("Deactivating async {0}.", this.DisplayName); + Log.Info("Deactivating async {0}.", DisplayName); if (IsActive || IsInitialized && close) { AttemptingDeactivation?.Invoke(this, new DeactivationEventArgs @@ -183,7 +183,7 @@ public virtual async Task TryCloseAsync(bool? dialogResult = null) [Obsolete("Override OnInitializedAsync")] protected virtual Task OnInitializeAsync(CancellationToken cancellationToken) { - Log.Info("Initializing async {0}.", this.DisplayName); + Log.Info("Initializing async {0}.", DisplayName); return Task.FromResult(true); } diff --git a/src/Caliburn.Micro.Core/SequentialResult.cs b/src/Caliburn.Micro.Core/SequentialResult.cs index e6858a087..59eab56ce 100644 --- a/src/Caliburn.Micro.Core/SequentialResult.cs +++ b/src/Caliburn.Micro.Core/SequentialResult.cs @@ -37,8 +37,7 @@ public void Execute(CoroutineExecutionContext context) private void ChildCompleted(object sender, ResultCompletionEventArgs args) { - var previous = sender as IResult; - if (previous != null) + if (sender is IResult previous) { previous.Completed -= ChildCompleted; } diff --git a/src/Caliburn.Micro.Core/SimpleContainer.cs b/src/Caliburn.Micro.Core/SimpleContainer.cs index 651e767ca..3e25e906b 100644 --- a/src/Caliburn.Micro.Core/SimpleContainer.cs +++ b/src/Caliburn.Micro.Core/SimpleContainer.cs @@ -67,7 +67,7 @@ public void RegisterPerRequest(Type service, string key, Type implementation) public void RegisterSingleton(Type service, string key, Type implementation) { object singleton = null; - RegisterHandler(service, key, container => singleton ?? (singleton = container.BuildInstance(implementation))); + RegisterHandler(service, key, container => (singleton ??= container.BuildInstance(implementation))); } /// @@ -158,7 +158,7 @@ public object GetInstance(Type service, string key) /// /// The service. /// The key. - /// True if a handler is registere; false otherwise. + /// True if a handler is registered; false otherwise. public bool HasHandler(Type service, string key) { return GetEntry(service, key) != null; diff --git a/src/Caliburn.Micro.Core/TaskExtensions.cs b/src/Caliburn.Micro.Core/TaskExtensions.cs index 0e3bf182f..8704d4302 100644 --- a/src/Caliburn.Micro.Core/TaskExtensions.cs +++ b/src/Caliburn.Micro.Core/TaskExtensions.cs @@ -1,15 +1,15 @@ -namespace Caliburn.Micro -{ - using System; - using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +namespace Caliburn.Micro +{ /// /// Extension methods to bring and together. /// public static class TaskExtensions { /// - /// Executes an asynchronous. + /// Executes an asynchronous. /// /// The coroutine to execute. /// The context to execute the coroutine within. @@ -20,7 +20,7 @@ public static Task ExecuteAsync(this IResult result, CoroutineExecutionContext c } /// - /// Executes an asynchronous. + /// Executes an asynchronous. /// /// The type of the result. /// The coroutine to execute. @@ -36,10 +36,9 @@ private static Task InternalExecuteAsync(IResult result, Corou { var taskSource = new TaskCompletionSource(); - EventHandler completed = null; - completed = (s, e) => + void OnCompleted(object s, ResultCompletionEventArgs e) { - result.Completed -= completed; + result.Completed -= OnCompleted; if (e.Error != null) { @@ -51,20 +50,19 @@ private static Task InternalExecuteAsync(IResult result, Corou } else { - var rr = result as IResult; - taskSource.SetResult(rr != null ? rr.Result : default(TResult)); + taskSource.SetResult(result is IResult rr ? rr.Result : default); } - }; + } try { IoC.BuildUp(result); - result.Completed += completed; + result.Completed += OnCompleted; result.Execute(context ?? new CoroutineExecutionContext()); } catch (Exception ex) { - result.Completed -= completed; + result.Completed -= OnCompleted; taskSource.SetException(ex); } @@ -72,7 +70,7 @@ private static Task InternalExecuteAsync(IResult result, Corou } /// - /// Encapsulates a task inside a couroutine. + /// Encapsulates a task inside a coroutine. /// /// The task. /// The coroutine that encapsulates the task. @@ -82,7 +80,7 @@ public static TaskResult AsResult(this Task task) } /// - /// Encapsulates a task inside a couroutine. + /// Encapsulates a task inside a coroutine. /// /// The type of the result. /// The task. diff --git a/src/Caliburn.Micro.Core/TaskResult.cs b/src/Caliburn.Micro.Core/TaskResult.cs index 8266bafe5..ea8fa970f 100644 --- a/src/Caliburn.Micro.Core/TaskResult.cs +++ b/src/Caliburn.Micro.Core/TaskResult.cs @@ -4,7 +4,7 @@ namespace Caliburn.Micro { /// - /// A couroutine that encapsulates an . + /// A coroutine that encapsulates an . /// public class TaskResult : IResult { @@ -54,7 +54,7 @@ protected virtual void OnCompleted(Task task) } /// - /// A couroutine that encapsulates an . + /// A coroutine that encapsulates an . /// /// The type of the result. public class TaskResult : TaskResult, IResult diff --git a/src/Caliburn.Micro.Core/ViewAware.cs b/src/Caliburn.Micro.Core/ViewAware.cs index ef6623dcd..5fd63f5b8 100644 --- a/src/Caliburn.Micro.Core/ViewAware.cs +++ b/src/Caliburn.Micro.Core/ViewAware.cs @@ -17,7 +17,7 @@ public class ViewAware : PropertyChangedBase, IViewAware public static readonly object DefaultContext = new object(); /// - /// The view chache for this instance. + /// The view cache for this instance. /// protected IDictionary Views { @@ -46,8 +46,7 @@ void IViewAware.AttachView(object view, object context) OnViewAttached(nonGeneratedView, context); ViewAttached(this, new ViewAttachedEventArgs { View = nonGeneratedView, Context = context }); - var activatable = this as IActivate; - if (activatable == null || activatable.IsActive) + if (this is not IActivate activatable || activatable.IsActive) { PlatformProvider.Current.ExecuteOnLayoutUpdated(nonGeneratedView, OnViewReady); } @@ -60,10 +59,9 @@ void IViewAware.AttachView(object view, object context) private static void AttachViewReadyOnActivated(IActivate activatable, object nonGeneratedView) { var viewReference = new WeakReference(nonGeneratedView); - AsyncEventHandler handler = null; - handler = (s, e) => + Task OnActivated(object s, ActivationEventArgs e) { - ((IActivate)s).Activated -= handler; + ((IActivate)s).Activated -= OnActivated; var view = viewReference.Target; if (view != null) { @@ -71,8 +69,9 @@ private static void AttachViewReadyOnActivated(IActivate activatable, object non } return Task.CompletedTask; - }; - activatable.Activated += handler; + } + + activatable.Activated += OnActivated; } /// @@ -107,8 +106,7 @@ protected virtual void OnViewReady(object view) /// The view. public virtual object GetView(object context = null) { - object view; - Views.TryGetValue(context ?? DefaultContext, out view); + Views.TryGetValue(context ?? DefaultContext, out object view); return view; } } diff --git a/src/Caliburn.Micro.Core/WeakValueDictionary.cs b/src/Caliburn.Micro.Core/WeakValueDictionary.cs index 2b550c366..19df0c299 100644 --- a/src/Caliburn.Micro.Core/WeakValueDictionary.cs +++ b/src/Caliburn.Micro.Core/WeakValueDictionary.cs @@ -16,8 +16,6 @@ internal class WeakValueDictionary : IDictionary private readonly Dictionary inner; private readonly WeakReference gcSentinel = new WeakReference(new object()); - #region Cleanup handling - private bool IsCleanupNeeded() { if (gcSentinel.Target == null) @@ -46,10 +44,6 @@ private void CleanIfNeeded() } } - #endregion - - #region Constructors - /// /// Initializes a new instance of the class that is empty, has the default initial capacity, and uses the default equality comparer for the key type. /// @@ -107,8 +101,6 @@ public WeakValueDictionary(int capacity, IEqualityComparer comparer) inner = new Dictionary(capacity, comparer); } - #endregion - /// /// Returns an enumerator that iterates through the . /// @@ -141,13 +133,8 @@ public void Clear() bool ICollection>.Contains(KeyValuePair item) { - TValue value; - if (!TryGetValue(item.Key, out value)) - { - return false; - } - - return value == item.Value; + return TryGetValue(item.Key, out TValue value) && + value == item.Value; } void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) @@ -173,18 +160,9 @@ void ICollection>.CopyTo(KeyValuePair[] bool ICollection>.Remove(KeyValuePair item) { - TValue value; - if (!TryGetValue(item.Key, out value)) - { - return false; - } - - if (value != item.Value) - { - return false; - } - - return inner.Remove(item.Key); + return TryGetValue(item.Key, out TValue value) && + value == item.Value && + inner.Remove(item.Key); } /// @@ -227,8 +205,7 @@ public void Add(TKey key, TValue value) /// public bool ContainsKey(TKey key) { - TValue dummy; - return TryGetValue(key, out dummy); + return TryGetValue(key, out _); } /// @@ -255,8 +232,7 @@ public bool TryGetValue(TKey key, out TValue value) { CleanIfNeeded(); - WeakReference wr; - if (!inner.TryGetValue(key, out wr)) + if (!inner.TryGetValue(key, out WeakReference wr)) { value = null; return false; @@ -286,8 +262,7 @@ public TValue this[TKey key] { get { - TValue result; - if (!TryGetValue(key, out result)) + if (!TryGetValue(key, out TValue result)) { throw new KeyNotFoundException(); } @@ -317,8 +292,6 @@ public ICollection Values get { return new ValueCollection(this); } } - #region Inner Types - private sealed class ValueCollection : ICollection { private readonly WeakValueDictionary inner; @@ -389,7 +362,5 @@ bool ICollection.IsReadOnly get { return true; } } } - - #endregion } } diff --git a/src/Caliburn.Micro.Maui.Tests/ParameterTests.cs b/src/Caliburn.Micro.Maui.Tests/ParameterTests.cs index 2f0ae3174..31dd9d324 100644 --- a/src/Caliburn.Micro.Maui.Tests/ParameterTests.cs +++ b/src/Caliburn.Micro.Maui.Tests/ParameterTests.cs @@ -1,10 +1,7 @@ -namespace Caliburn.Micro.Maui.Tests -{ - using Microsoft.Maui.Controls; - using Moq; - using Xunit; - +using Moq; +namespace Caliburn.Micro.Maui.Tests +{ public class ParameterTests { [Fact] diff --git a/src/Caliburn.Micro.Maui.Tests/ViewModelLocatorTests.cs b/src/Caliburn.Micro.Maui.Tests/ViewModelLocatorTests.cs index a089bcded..4734a5996 100644 --- a/src/Caliburn.Micro.Maui.Tests/ViewModelLocatorTests.cs +++ b/src/Caliburn.Micro.Maui.Tests/ViewModelLocatorTests.cs @@ -56,7 +56,7 @@ public void ConfigureTypeMappingsShouldThrowWhenDefaultSubNamespaceForViewsIsNul [Fact] - public void COnfigureTypeMappingsWithDefaultValuesShouldNotThrow() + public void ConfigureTypeMappingsWithDefaultValuesShouldNotThrow() { var typeMappingConfiguration = new TypeMappingConfiguration(); diff --git a/src/Caliburn.Micro.Platform.Core/AssemblySource.cs b/src/Caliburn.Micro.Platform.Core/AssemblySource.cs index 1d90fb78c..2d2c870f1 100644 --- a/src/Caliburn.Micro.Platform.Core/AssemblySource.cs +++ b/src/Caliburn.Micro.Platform.Core/AssemblySource.cs @@ -61,10 +61,10 @@ public static void AddRange(IEnumerable assemblies) public static class AssemblySourceCache { private static bool isInstalled; - private static readonly IDictionary TypeNameCache = new Dictionary(); + private static readonly IDictionary TypeNameCache = new Dictionary(); /// - /// Extracts the types from the spezified assembly for storing in the cache. + /// Extracts the types from the specified assembly for storing in the cache. /// public static Func> ExtractTypes = assembly => assembly.ExportedTypes diff --git a/src/Caliburn.Micro.Platform.Core/RegExHelper.cs b/src/Caliburn.Micro.Platform.Core/RegExHelper.cs index 678e8a34f..a547391b5 100644 --- a/src/Caliburn.Micro.Platform.Core/RegExHelper.cs +++ b/src/Caliburn.Micro.Platform.Core/RegExHelper.cs @@ -1,6 +1,4 @@ -using System; - -namespace Caliburn.Micro +namespace Caliburn.Micro { /// /// Helper class for encoding strings to regular expression patterns @@ -10,10 +8,63 @@ public static class RegExHelper /// /// Regular expression pattern for valid name /// - public const string NameRegEx = @"[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_][\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}_]*"; + /// + /// Match a single character present in the list [\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_] + /// + /// + /// Regex + /// Description + /// + /// + /// \p{Lu} + /// matches an uppercase letter that has a lowercase variant + /// + /// + /// \p{Ll} + /// matches a lowercase letter that has an uppercase variant + /// + /// + /// \p{Lt} + /// matches a letter that appears at the start of a word when only the first letter of the word is capitalized + /// + /// + /// \p{Lm} + /// matches a special character that is used like a letter + /// + /// + /// \p{Lo} + /// matches a letter or ideograph that does not have lowercase and uppercase variants + /// + /// + /// \p{Nl} + /// matches a number that looks like a letter, such as a Roman numeral + /// + /// + /// _ + /// matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive) + /// + /// + /// + /// Match a single character present in the list [\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}_]
+ /// * matches the previous token between zero and unlimited times, as many times as possible, giving back as needed (greedy)
+ /// \p{Lu} matches an uppercase letter that has a lowercase variant
+ /// \p{Ll} matches a lowercase letter that has an uppercase variant
+ /// \p{Lt} matches a letter that appears at the start of a word when only the first letter of the word is capitalized
+ /// \p{Lm} matches a special character that is used like a letter
+ /// \p{Lo} matches a letter or ideograph that does not have lowercase and uppercase variants
+ /// \p{Nl} matches a number that looks like a letter, such as a Roman numeral
+ /// \p{Mn} matches a character intended to be combined with another character without taking up extra space (e.g. accents, umlauts, etc.)
+ /// \p{Mc} matches a character intended to be combined with another character that takes up extra space (vowel signs in many Eastern languages)
+ /// \p{Nd} matches a digit zero through nine in any script except ideographic scripts
+ /// \p{Pc} matches a punctuation character such as an underscore that connects words
+ /// \p{Cf} matches invisible formatting indicator
+ /// _ matches the character _ with index 9510 (5F16 or 1378) literally (case sensitive)
+ ///
+ public const string NameRegEx = @"[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_]" + + @"[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}_]*"; /// - /// Regular expression pattern for subnamespace (including dot) + /// Regular expression pattern for SubNamespace (including dot) /// public const string SubNamespaceRegEx = NameRegEx + @"\."; @@ -30,7 +81,7 @@ public static class RegExHelper /// Regular expression capture group with the specified group name public static string GetCaptureGroup(string groupName, string regEx) { - return String.Concat(@"(?<", groupName, ">", regEx, ")"); + return string.Concat(@"(?<", groupName, ">", regEx, ")"); } /// @@ -40,12 +91,12 @@ public static string GetCaptureGroup(string groupName, string regEx) /// Namespace converted to a regular expression public static string NamespaceToRegEx(string srcNamespace) { - //Need to escape the "." as it's a special character in regular expression syntax - var nsencoded = srcNamespace.Replace(".", @"\."); + // Need to escape the "." as it's a special character in regular expression syntax + var encodedNamespace = srcNamespace.Replace(".", @"\."); - //Replace "*" wildcard with regular expression syntax - nsencoded = nsencoded.Replace(@"*\.", NamespaceRegEx); - return nsencoded; + // Replace "*" wildcard with regular expression syntax + encodedNamespace = encodedNamespace.Replace(@"*\.", NamespaceRegEx); + return encodedNamespace; } /// @@ -68,4 +119,4 @@ public static string GetNamespaceCaptureGroup(string groupName) return GetCaptureGroup(groupName, NamespaceRegEx); } } -} \ No newline at end of file +} diff --git a/src/Caliburn.Micro.Platform.Core/StringSplitter.cs b/src/Caliburn.Micro.Platform.Core/StringSplitter.cs index dca9e39c5..c4fe63325 100644 --- a/src/Caliburn.Micro.Platform.Core/StringSplitter.cs +++ b/src/Caliburn.Micro.Platform.Core/StringSplitter.cs @@ -122,7 +122,7 @@ public static string[] SplitParameters(string parameters) //The only commas to be considered as parameter separators are outside: //- Strings //- Square brackets (to ignore indexers) - //- Parantheses (to ignore method invocations) + //- Parentheses (to ignore method invocations) //- Curly brackets (to ignore initializers and Bindings) list.Add(builder.ToString()); builder.Length = 0; diff --git a/src/Caliburn.Micro.Platform.Core/TypeMappingConfiguration.cs b/src/Caliburn.Micro.Platform.Core/TypeMappingConfiguration.cs index 58589a56d..36831de74 100644 --- a/src/Caliburn.Micro.Platform.Core/TypeMappingConfiguration.cs +++ b/src/Caliburn.Micro.Platform.Core/TypeMappingConfiguration.cs @@ -8,12 +8,12 @@ public class TypeMappingConfiguration { /// - /// The default subnamespace for Views. Used for creating default subnamespace mappings. Defaults to "Views". + /// The default SubNamespace for Views. Used for creating default SubNamespace mappings. Defaults to "Views". /// public string DefaultSubNamespaceForViews { get; set; } = "Views"; /// - /// The default subnamespace for ViewModels. Used for creating default subnamespace mappings. Defaults to "ViewModels". + /// The default SubNamespace for ViewModels. Used for creating default SubNamespace mappings. Defaults to "ViewModels". /// public string DefaultSubNamespaceForViewModels { get; set; } = "ViewModels"; @@ -43,4 +43,4 @@ public class TypeMappingConfiguration /// public string ViewModelSuffix { get; set; } = "ViewModel"; } -} \ No newline at end of file +} diff --git a/src/Caliburn.Micro.Platform.Tests/AssemblyCacheTests.cs b/src/Caliburn.Micro.Platform.Tests/AssemblyCacheTests.cs index 72fa67271..8a1549115 100644 --- a/src/Caliburn.Micro.Platform.Tests/AssemblyCacheTests.cs +++ b/src/Caliburn.Micro.Platform.Tests/AssemblyCacheTests.cs @@ -1,6 +1,4 @@ -using System; -using System.Globalization; -using Xunit; +using Xunit; namespace Caliburn.Micro.Platform.Tests { diff --git a/src/Caliburn.Micro.Platform.Tests/Caliburn.Micro.Platform.Tests.csproj b/src/Caliburn.Micro.Platform.Tests/Caliburn.Micro.Platform.Tests.csproj index 81d7ca677..a306be123 100644 --- a/src/Caliburn.Micro.Platform.Tests/Caliburn.Micro.Platform.Tests.csproj +++ b/src/Caliburn.Micro.Platform.Tests/Caliburn.Micro.Platform.Tests.csproj @@ -31,12 +31,6 @@ - - - - - - diff --git a/src/Caliburn.Micro.Platform.Tests/ParserTests.cs b/src/Caliburn.Micro.Platform.Tests/ParserTests.cs index f20324a76..00a1c344e 100644 --- a/src/Caliburn.Micro.Platform.Tests/ParserTests.cs +++ b/src/Caliburn.Micro.Platform.Tests/ParserTests.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Globalization; using Xunit; namespace Caliburn.Micro.Platform.Tests diff --git a/src/Caliburn.Micro.Platform.Tests/ScopeNamingRouteTests.cs b/src/Caliburn.Micro.Platform.Tests/ScopeNamingRouteTests.cs index 1403eed06..8bfe8fff7 100644 --- a/src/Caliburn.Micro.Platform.Tests/ScopeNamingRouteTests.cs +++ b/src/Caliburn.Micro.Platform.Tests/ScopeNamingRouteTests.cs @@ -28,8 +28,7 @@ public void CorrectlyGetsAddedHop() var d1 = new DependencyObject(); var d2 = new DependencyObject(); route.AddHop(d1, d2); - DependencyObject target; - var result = route.TryGetHop(d1, out target); + var result = route.TryGetHop(d1, out DependencyObject target); Assert.True(result); Assert.Same(d2, target); } @@ -55,9 +54,8 @@ public void GetsAllHopsAdded() }; var source = d1; - DependencyObject target; - while (route.TryGetHop(source, out target)) + while (route.TryGetHop(source, out DependencyObject target)) { all.Remove(target); source = target; diff --git a/src/Caliburn.Micro.Platform.Tests/ViewModelLocatorTests.cs b/src/Caliburn.Micro.Platform.Tests/ViewModelLocatorTests.cs index efa9f1596..8b3fabda4 100644 --- a/src/Caliburn.Micro.Platform.Tests/ViewModelLocatorTests.cs +++ b/src/Caliburn.Micro.Platform.Tests/ViewModelLocatorTests.cs @@ -59,7 +59,7 @@ public void ConfigureTypeMappingsShouldThrowWhenDefaultSubNamespaceForViewsIsNul [Fact] - public void COnfigureTypeMappingsWithDefaultValuesShouldNotThrow() + public void ConfigureTypeMappingsWithDefaultValuesShouldNotThrow() { var typeMappingConfiguration = new TypeMappingConfiguration(); diff --git a/src/Caliburn.Micro.Platform/Platforms/Maui/Android/ActivityLifecycleCallbackHandler.cs b/src/Caliburn.Micro.Platform/Platforms/Maui/Android/ActivityLifecycleCallbackHandler.cs index b374e436c..df3b5e14b 100644 --- a/src/Caliburn.Micro.Platform/Platforms/Maui/Android/ActivityLifecycleCallbackHandler.cs +++ b/src/Caliburn.Micro.Platform/Platforms/Maui/Android/ActivityLifecycleCallbackHandler.cs @@ -109,7 +109,7 @@ public void OnActivityStopped(Activity activity) ActivityStopped(this, new ActivityEventArgs(activity)); } - public void OnActivityPostCreated(Activity activity, Bundle? savedInstanceState) + public void OnActivityPostCreated(Activity activity, Bundle savedInstanceState) { } @@ -144,7 +144,7 @@ public void OnActivityPostStopped(Activity activity) } - public void OnActivityPreCreated(Activity activity, Bundle? savedInstanceState) + public void OnActivityPreCreated(Activity activity, Bundle savedInstanceState) { }