Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Applying best practice #871

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ public abstract class ConductorBaseWithActiveItem<T> : ConductorBase<T>, IConduc
private T _activeItem;

/// <summary>
/// The currently active item.
/// Gets or sets the currently active item.
/// </summary>
public T ActiveItem {
get => _activeItem;
set => ActivateItemAsync(value, CancellationToken.None);
}

/// <summary>
/// The currently active item.
/// Gets or sets the currently active item.
/// </summary>
/// <value></value>
/// <value>
/// The currently active item.
/// </value>
object IHaveActiveItem.ActiveItem {
get => ActiveItem;
set => ActiveItem = (T)value;
Expand Down
4 changes: 2 additions & 2 deletions src/Caliburn.Micro.Core/Conductor/Contracts/ICloseResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Caliburn.Micro;
/// </summary>
public interface ICloseResult<T> {
/// <summary>
/// Indicates which children shbould close if the parent cannot.
/// Gets list of children that should close if the parent cannot.
/// </summary>
IEnumerable<T> Children { get; }

/// <summary>
/// Indicates whether a close can occur.
/// Gets a value indicating whether a close can occur.
/// </summary>
bool CloseCanOccur { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// </summary>
public interface IHaveActiveItem {
/// <summary>
/// The currently active item.
/// Gets or sets the currently active item.
/// </summary>
object ActiveItem { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Caliburn.Micro;
/// </summary>
public class ActivationProcessedEventArgs : EventArgs {
/// <summary>
/// The item whose activation was processed.
/// Gets or sets the item whose activation was processed.
/// </summary>
public object Item { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
/// </summary>
public class CoroutineExecutionContext {
/// <summary>
/// The source from which the message originates.
/// Gets or sets the source from which the message originates.
/// </summary>
public object Source { get; set; }

/// <summary>
/// The view associated with the target.
/// Gets or sets the view associated with the target.
/// </summary>
public object View { get; set; }

/// <summary>
/// The instance on which the action is invoked.
/// Gets or sets the instance on which the action is invoked.
/// </summary>
public object Target { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class EventAggregatorExtensions {
/// Subscribes an instance to all events declared through implementations of <see cref = "IHandle{T}" />.
/// </summary>
/// <remarks>The subscription is invoked on the thread chosen by the publisher.</remarks>
/// <param name="eventAggregator">The EventAggregator.</param>
/// <param name = "subscriber">The instance to subscribe for event publication.</param>
public static void SubscribeOnPublishedThread(this IEventAggregator eventAggregator, object subscriber)
=> eventAggregator.Subscribe(subscriber, f => f());
Expand All @@ -20,6 +21,7 @@ public static void SubscribeOnPublishedThread(this IEventAggregator eventAggrega
/// Subscribes an instance to all events declared through implementations of <see cref = "IHandle{T}" />.
/// </summary>
/// <remarks>The subscription is invoked on the thread chosen by the publisher.</remarks>
/// <param name="eventAggregator">The event aggregator.</param>
/// <param name = "subscriber">The instance to subscribe for event publication.</param>
[Obsolete("Use SubscribeOnPublishedThread")]
public static void Subscribe(this IEventAggregator eventAggregator, object subscriber)
Expand All @@ -29,6 +31,7 @@ public static void Subscribe(this IEventAggregator eventAggregator, object subsc
/// Subscribes an instance to all events declared through implementations of <see cref = "IHandle{T}" />.
/// </summary>
/// <remarks>The subscription is invoked on a new background thread.</remarks>
/// <param name="eventAggregator">The event aggregator.</param>
/// <param name = "subscriber">The instance to subscribe for event publication.</param>
public static void SubscribeOnBackgroundThread(this IEventAggregator eventAggregator, object subscriber)
=> eventAggregator.Subscribe(subscriber, f => Task.Factory.StartNew(f, default, TaskCreationOptions.None, TaskScheduler.Default));
Expand All @@ -37,6 +40,7 @@ public static void SubscribeOnBackgroundThread(this IEventAggregator eventAggreg
/// Subscribes an instance to all events declared through implementations of <see cref = "IHandle{T}" />.
/// </summary>
/// <remarks>The subscription is invoked on the UI thread.</remarks>
/// <param name="eventAggregator">The event aggregator.</param>
/// <param name = "subscriber">The instance to subscribe for event publication.</param>
public static void SubscribeOnUIThread(this IEventAggregator eventAggregator, object subscriber)
=> eventAggregator.Subscribe(
Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Core/Extensions/Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Caliburn.Micro;
/// </summary>
public static class Execute {
/// <summary>
/// Indicates whether or not the framework is in design-time mode.
/// Gets a value indicating whether or not the framework is in design-time mode.
/// </summary>
public static bool InDesignMode
=> PlatformProvider.Current.InDesignMode;
Expand Down
6 changes: 3 additions & 3 deletions src/Caliburn.Micro.Core/IoC/ExtensionPoints/IoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ namespace Caliburn.Micro;
/// </summary>
public static class IoC {
/// <summary>
/// Gets an instance by type and key.
/// Gets or sets func to get an instance by type and key.
/// </summary>
public static Func<Type, string, object> GetInstance { get; set; }
= (service, key)
=> throw new InvalidOperationException("IoC is not initialized.");

/// <summary>
/// Gets all instances of a particular type.
/// Gets or sets func to get all instances of a particular type.
/// </summary>
public static Func<Type, IEnumerable<object>> GetAllInstances { get; set; }
= service
=> throw new InvalidOperationException("IoC is not initialized.");

/// <summary>
/// Passes an existing instance to the IoC container to enable dependencies to be injected.
/// Gets or sets action to be passes an existing instance to the IoC container to enable dependencies to be injected.
/// </summary>
public static Action<object> BuildUp { get; set; }
= instance
Expand Down
14 changes: 7 additions & 7 deletions src/Caliburn.Micro.Core/IoC/Extensions/ContainerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class ContainerExtensions {
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
/// <param name="container">The container.</param>
/// <param name="key">The key.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer Singleton<TImplementation>(this SimpleContainer container, string key = null)
=> Singleton<TImplementation, TImplementation>(container, key);

Expand All @@ -26,7 +26,7 @@ public static SimpleContainer Singleton<TImplementation>(this SimpleContainer co
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
/// <param name="container">The container.</param>
/// <param name="key">The key.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer Singleton<TService, TImplementation>(this SimpleContainer container, string key = null)
where TImplementation : TService {
container.RegisterSingleton(typeof(TService), key, typeof(TImplementation));
Expand All @@ -40,7 +40,7 @@ public static SimpleContainer Singleton<TService, TImplementation>(this SimpleCo
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
/// <param name="container">The container.</param>
/// <param name="key">The key.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer PerRequest<TImplementation>(this SimpleContainer container, string key = null)
=> PerRequest<TImplementation, TImplementation>(container, key);

Expand All @@ -51,7 +51,7 @@ public static SimpleContainer PerRequest<TImplementation>(this SimpleContainer c
/// <typeparam name="TImplementation">The type of the implementation.</typeparam>
/// <param name="container">The container.</param>
/// <param name="key">The key.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer PerRequest<TService, TImplementation>(this SimpleContainer container, string key = null)
where TImplementation : TService {
container.RegisterPerRequest(typeof(TService), key, typeof(TImplementation));
Expand All @@ -65,7 +65,7 @@ public static SimpleContainer PerRequest<TService, TImplementation>(this SimpleC
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="container">The container.</param>
/// <param name="instance">The instance.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer Instance<TService>(this SimpleContainer container, TService instance) {
container.RegisterInstance(typeof(TService), null, instance);

Expand All @@ -78,7 +78,7 @@ public static SimpleContainer Instance<TService>(this SimpleContainer container,
/// <typeparam name="TService">The type of the service.</typeparam>
/// <param name="container">The container.</param>
/// <param name="handler">The handler.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
K4PS3 marked this conversation as resolved.
Show resolved Hide resolved
public static SimpleContainer Handler<TService>(
this SimpleContainer container,
Func<SimpleContainer, object> handler) {
Expand All @@ -94,7 +94,7 @@ public static SimpleContainer Handler<TService>(
/// <param name="container">The container.</param>
/// <param name="assembly">The assembly.</param>
/// <param name="filter">The type filter.</param>
/// <returns>The container.</returns>
/// <returns>The <paramref name="container"/>.</returns>
public static SimpleContainer AllTypesOf<TService>(
this SimpleContainer container,
Assembly assembly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace Caliburn.Micro;
/// </summary>
public interface IPlatformProvider {
/// <summary>
/// Indicates whether or not the framework is in design-time mode.
/// Gets a value indicating whether or not the framework is in design-time mode.
/// </summary>
bool InDesignMode { get; }

/// <summary>
/// Whether or not classes should execute property change notications on the UI thread.
/// Gets a value indicating whether or not classes should execute property change notications on the UI thread.
/// </summary>
bool PropertyChangeNotificationsOnUIThread { get; }

Expand Down
4 changes: 0 additions & 4 deletions src/Caliburn.Micro.Core/Result/Extensions/ResultExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ public static class ResultExtensions {
/// </summary>
/// <param name="result">The result to decorate.</param>
/// <param name="coroutine">The coroutine to execute when <paramref name="result"/> was canceled.</param>
/// <returns></returns>
public static IResult WhenCancelled(this IResult result, Func<IResult> coroutine)
=> new ContinueResultDecorator(result, coroutine);

/// <summary>
/// Overrides <see cref="ResultCompletionEventArgs.WasCancelled"/> of the decorated <paramref name="result"/> instance.
/// </summary>
/// <param name="result">The result to decorate.</param>
/// <returns></returns>
public static IResult OverrideCancel(this IResult result)
=> new OverrideCancelResultDecorator(result);

Expand All @@ -31,7 +29,6 @@ public static IResult OverrideCancel(this IResult result)
/// <param name="result">The result to decorate.</param>
/// <param name="rescue">The rescue coroutine.</param>
/// <param name="cancelResult">Set to true to cancel the result after executing rescue.</param>
/// <returns></returns>
public static IResult Rescue<TException>(this IResult result, Func<TException, IResult> rescue, bool cancelResult = true)
where TException : Exception
=> new RescueResultDecorator<TException>(result, rescue, cancelResult);
Expand All @@ -42,7 +39,6 @@ public static IResult Rescue<TException>(this IResult result, Func<TException, I
/// <param name="result">The result to decorate.</param>
/// <param name="rescue">The rescue coroutine.</param>
/// <param name="cancelResult">Set to true to cancel the result after executing rescue.</param>
/// <returns></returns>
public static IResult Rescue(this IResult result, Func<Exception, IResult> rescue, bool cancelResult = true)
=> Rescue<Exception>(result, rescue, cancelResult);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Caliburn.Micro;
/// </summary>
public class ActivationEventArgs : EventArgs {
/// <summary>
/// Indicates whether the sender was initialized in addition to being activated.
/// Gets or sets a value indicating whether the sender was initialized in addition to being activated.
/// </summary>
public bool WasInitialized { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Caliburn.Micro;
/// </summary>
public class DeactivationEventArgs : EventArgs {
/// <summary>
/// Indicates whether the sender was closed in addition to being deactivated.
/// Gets or sets a value indicating whether the sender was closed in addition to being deactivated.
/// </summary>
public bool WasClosed { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@

namespace Caliburn.Micro;

/// <summary>
/// Async Event Handler.
/// </summary>
/// <typeparam name="TEventArgs">The Event Args type.</typeparam>
/// <param name="sender">Event source.</param>
/// <param name="e">Event argument.</param>
/// <returns>Task.</returns>
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e)
where TEventArgs : EventArgs;
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@

namespace Caliburn.Micro;

/// <summary>
/// Async EventHandler Extensions.
/// </summary>
public static class AsyncEventHandlerExtensions {
/// <summary>
/// Get Invocation List of AsyncEventHandler.
/// </summary>
/// <typeparam name="TEventArgs">The Event args type.</typeparam>
/// <param name="handler">Async EventHandler.</param>
/// <returns>List of AsyncEventHandler.</returns>
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(this AsyncEventHandler<TEventArgs> handler)
where TEventArgs : EventArgs
=> handler.GetInvocationList().Cast<AsyncEventHandler<TEventArgs>>();

/// <summary>
/// Invoke all handlers of AsyncEventHandler.
/// </summary>
/// <typeparam name="TEventArgs">The Event args type.</typeparam>
/// <param name="handler">Async EventHandler.</param>
/// <param name="sender">The event source.</param>
/// <param name="e">The Event args.</param>
/// <returns>Task.</returns>
public static Task InvokeAllAsync<TEventArgs>(this AsyncEventHandler<TEventArgs> handler, object sender, TEventArgs e)
where TEventArgs : EventArgs
=> Task.WhenAll(
Expand Down
24 changes: 12 additions & 12 deletions src/Caliburn.Micro.Core/Screen/Extensions/ScreenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public static Task CloseItemAsync<T>(this ConductorBase<T> conductor, T item, Ca
where T : class
=> conductor.DeactivateItemAsync(item, true, cancellationToken);

///<summary>
/// <summary>
/// Activates a child whenever the specified parent is activated.
///</summary>
///<param name="child">The child to activate.</param>
///<param name="parent">The parent whose activation triggers the child's activation.</param>
/// </summary>
/// <param name="child">The child to activate.</param>
/// <param name="parent">The parent whose activation triggers the child's activation.</param>
public static void ActivateWith(this IActivate child, IActivate parent) {
var childReference = new WeakReference(child);

Expand All @@ -103,11 +103,11 @@ async Task OnParentActivated(object s, ActivationEventArgs e) {
parent.Activated += OnParentActivated;
}

///<summary>
/// <summary>
/// Deactivates a child whenever the specified parent is deactivated.
///</summary>
///<param name="child">The child to deactivate.</param>
///<param name="parent">The parent whose deactivation triggers the child's deactivation.</param>
/// </summary>
/// <param name="child">The child to deactivate.</param>
/// <param name="parent">The parent whose deactivation triggers the child's deactivation.</param>
public static void DeactivateWith(this IDeactivate child, IDeactivate parent) {
var childReference = new WeakReference(child);

Expand All @@ -123,11 +123,11 @@ async Task OnParentDeactivated(object s, DeactivationEventArgs e) {
parent.Deactivated += OnParentDeactivated;
}

///<summary>
/// <summary>
/// Activates and Deactivates a child whenever the specified parent is Activated or Deactivated.
///</summary>
///<param name="child">The child to activate/deactivate.</param>
///<param name="parent">The parent whose activation/deactivation triggers the child's activation/deactivation.</param>
/// </summary>
/// <param name="child">The child to activate/deactivate.</param>
/// <param name="parent">The parent whose activation/deactivation triggers the child's activation/deactivation.</param>
public static void ConductWith<TChild, TParent>(this TChild child, TParent parent)
where TChild : IActivate, IDeactivate
where TParent : IActivate, IDeactivate {
Expand Down
2 changes: 1 addition & 1 deletion src/Caliburn.Micro.Core/Types/INotifyPropertyChangedEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Caliburn.Micro;
/// </summary>
public interface INotifyPropertyChangedEx : INotifyPropertyChanged {
/// <summary>
/// Enables/Disables property change notification.
/// Gets or sets a value indicating whether to enable/Disable property change notification.
/// </summary>
bool IsNotifying { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Caliburn.Micro;
/// </summary>
public class ViewAttachedEventArgs : EventArgs {
/// <summary>
/// The view.
/// Gets or sets the view.
/// </summary>
public object View { get; set; }

/// <summary>
/// The context.
/// Gets or sets the context.
/// </summary>
public object Context { get; set; }
}
1 change: 1 addition & 0 deletions src/Caliburn.Micro.Core/ViewAware/ViewAware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected virtual void OnViewAttached(object view, object context) {
/// <summary>
/// Called when an attached view's Loaded event fires.
/// </summary>
/// <param name="view">The loaded view.</param>
protected virtual void OnViewLoaded(object view) {
}

Expand Down