Skip to content

Commit

Permalink
chore: adding missing XML docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Feb 24, 2024
1 parent 285e389 commit ae26f82
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 10 deletions.
11 changes: 11 additions & 0 deletions src/Maui/Prism.Maui/AppModel/IApplicationLifecycleAware.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
namespace Prism.AppModel;


/// <summary>
/// Defines methods for responding to application lifecycle events.
/// </summary>
public interface IApplicationLifecycleAware
{
/// <summary>
/// Called when the application resumes from a suspended state.
/// </summary>
void OnResume();

/// <summary>
/// Called when the application enters a sleep or suspended state.
/// </summary>
void OnSleep();
}
4 changes: 4 additions & 0 deletions src/Maui/Prism.Maui/Behaviors/MultiPageActiveAwareBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

namespace Prism.Behaviors;

/// <summary>
/// Provides behaviors for types of <see cref="MultiPage{T}"/>
/// </summary>
/// <typeparam name="T">The typeof <see cref="Page"/>.</typeparam>
public class MultiPageActiveAwareBehavior<T> : BehaviorBase<MultiPage<T>> where T : Page
{
/// <inheritDoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System.ComponentModel;
using Prism.Common;
using Prism.Extensions;
using PropertyChangingEventArgs = Microsoft.Maui.Controls.PropertyChangingEventArgs;

namespace Prism.Behaviors;

/// <summary>
/// Provides activation and deactivation for <see cref="IActiveAware"/> ViewModels that may be set as the CurrentPage.
/// </summary>
public class NavigationPageActiveAwareBehavior : BehaviorBase<NavigationPage>
{
/// <inheritDoc/>
protected override void OnAttachedTo(NavigationPage bindable)
{
bindable.PropertyChanged += NavigationPage_PropertyChanged;
Expand All @@ -21,6 +24,7 @@ private void OnParentChanged(object sender, EventArgs e)
SetActiveAware();
}

/// <inheritDoc/>
protected override void OnDetachingFrom(NavigationPage bindable)
{
bindable.PropertyChanged -= NavigationPage_PropertyChanged;
Expand Down
99 changes: 97 additions & 2 deletions src/Maui/Prism.Maui/Dialogs/Xaml/DialogLayout.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,173 @@
namespace Prism.Dialogs.Xaml;
namespace Prism.Dialogs.Xaml;

/// <summary>
/// Provides attached properties for customizing the layout and behavior of dialogs in .NET MAUI.
/// </summary>
public static class DialogLayout
{
/// <summary>
/// Gets the key for specifying or retrieving popup overlay style from Application Resources.
/// </summary>
public const string PopupOverlayStyle = "PrismDialogMaskStyle";

/// <summary>
/// Attached property that specifies the desired relative width of the dialog.
/// </summary>
public static readonly BindableProperty RelativeWidthRequestProperty =
BindableProperty.CreateAttached("RelativeWidthRequest", typeof(double?), typeof(DialogLayout), null);

/// <summary>
/// Gets the value of the RelativeWidthRequest attached property from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the property value from.</param>
/// <returns>The value of the RelativeWidthRequest property, or null if not set.</returns>
public static double? GetRelativeWidthRequest(BindableObject bindable) =>
(double?)bindable.GetValue(RelativeWidthRequestProperty);

/// <summary>
/// Sets the value of the RelativeWidthRequest attached property on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the property value on.</param>
/// <param name="value">The desired relative width of the dialog.</param>
public static void SetRelativeWidthRequest(BindableObject bindable, double? value) =>
bindable.SetValue(RelativeWidthRequestProperty, value);

/// <summary>
/// Attached property that specifies the desired relative height of the dialog.
/// </summary>
public static readonly BindableProperty RelativeHeightRequestProperty =
BindableProperty.CreateAttached("RelativeHeightRequest", typeof(double?), typeof(DialogLayout), null);

/// <summary>
/// Gets the value of the RelativeHeightRequest attached property from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the property value from.</param>
/// <returns>The value of the RelativeHeightRequest property, or null if not set.</returns>
public static double? GetRelativeHeightRequest(BindableObject bindable) =>
(double?)bindable.GetValue(RelativeHeightRequestProperty);

/// <summary>
/// Sets the value of the RelativeHeightRequest attached property on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the property value on.</param>
/// <param name="value">The desired relative height of the dialog.</param>
public static void SetRelativeHeightRequest(BindableObject bindable, double? value) =>
bindable.SetValue(RelativeHeightRequestProperty, value);

/// <summary>
/// Attached property that specifies the layout bounds of the dialog within its parent.
/// </summary>
public static readonly BindableProperty LayoutBoundsProperty =
BindableProperty.CreateAttached("LayoutBounds", typeof(Rect), typeof(DialogLayout), new Rect(0.5, 0.5, -1, -1));

/// <summary>
/// Gets the value of the LayoutBounds attached property from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the property value from.</param>
/// <returns>The layout bounds of the dialog.</returns>
public static Rect GetLayoutBounds(BindableObject bindable) =>
(Rect)bindable.GetValue(LayoutBoundsProperty);

/// <summary>
/// Sets the value of the LayoutBounds attached property on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the property value on.</param>
/// <param name="value">The desired layout bounds for the dialog.</param>
public static void SetLayoutBounds(BindableObject bindable, Rect value) =>
bindable.SetValue(LayoutBoundsProperty, value);

/// <summary>
/// Attached property that specifies the style to apply to the dialog mask (background overlay).
/// </summary>
public static readonly BindableProperty MaskStyleProperty =
BindableProperty.CreateAttached("MaskStyle", typeof(Style), typeof(DialogLayout), null);

/// <summary>
/// Gets the style applied to the dialog mask (background overlay) from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the mask style from.</param>
/// <returns>The style applied to the dialog mask, or null if not set.</returns>
public static Style GetMaskStyle(BindableObject bindable) =>
(Style)bindable.GetValue(MaskStyleProperty);

/// <summary>
/// Sets the style to be applied to the dialog mask (background overlay) on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the mask style on.</param>
/// <param name="value">The style to apply to the dialog mask.</param>
public static void SetMaskStyle(BindableObject bindable, Style value) =>
bindable.SetValue(MaskStyleProperty, value);

/// <summary>
/// Attached property that specifies the View to be used as the dialog mask (background overlay).
/// </summary>
public static readonly BindableProperty MaskProperty =
BindableProperty.CreateAttached("Mask", typeof(View), typeof(DialogLayout), null);

/// <summary>
/// Gets the View used as the dialog mask (background overlay) from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the mask view from.</param>
/// <returns>The View used as the dialog mask, or null if not set.</returns>
public static View GetMask(BindableObject bindable) =>
(View)bindable.GetValue(MaskProperty);

/// <summary>
/// Sets the View to be used as the dialog mask (background overlay) on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the mask view on.</param>
/// <param name="value">The View to use as the dialog mask.</param>
public static void SetMask(BindableObject bindable, View value) =>
bindable.SetValue(MaskProperty, value);

/// <summary>
/// Attached property that specifies whether a dialog should use a mask (background overlay).
/// </summary>
public static readonly BindableProperty UseMaskProperty =
BindableProperty.CreateAttached("UseMask", typeof(bool?), typeof(DialogLayout), null);

/// <summary>
/// Gets whether a mask is used for the dialog from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the mask usage from.</param>
/// <returns>True if a mask is used for the dialog, false if not, or null if not explicitly set.</returns>
public static bool? GetUseMask(BindableObject bindable)
{
var value = bindable.GetValue(UseMaskProperty);
if (value is bool boolean)
return boolean;

return true;
return true; // Default to using a mask if not explicitly set
}

/// <summary>
/// Sets whether a mask should be used for the dialog on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the mask usage on.</param>
/// <param name="value">True to use a mask for the dialog, false to not use a mask, or null to use the default behavior.</param>
public static void SetUseMask(BindableObject bindable, bool? value) =>
bindable.SetValue(UseMaskProperty, value);

/// <summary>
/// Attached property that specifies whether the dialog should close when the background is tapped.
/// </summary>
public static readonly BindableProperty CloseOnBackgroundTappedProperty =
BindableProperty.CreateAttached("CloseOnBackgroundTapped", typeof(bool?), typeof(DialogLayout), null);

/// <summary>
/// Gets whether the dialog closes when the background is tapped from the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to get the close-on-background-tap behavior from.</param>
/// <returns>True if the dialog closes on background tap, false if not, or null if not explicitly set.</returns>
public static bool? GetCloseOnBackgroundTapped(BindableObject bindable) =>
(bool?)bindable.GetValue(CloseOnBackgroundTappedProperty);

/// <summary>
/// Sets whether the dialog should close when the background is tapped on the specified BindableObject.
/// </summary>
/// <param name="bindable">The BindableObject to set the close-on-background-tap behavior on.</param>
/// <param name="value">True to close the dialog on background tap, false to not close on background tap, or null to use the default behavior.</param>
public static void SetCloseOnBackgroundTapped(BindableObject bindable, bool? value) =>
bindable.SetValue(CloseOnBackgroundTappedProperty, value);

}
18 changes: 15 additions & 3 deletions src/Prism.Core/Common/MulticastExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

Expand All @@ -8,7 +8,7 @@ namespace Prism.Common;
/// <summary>
/// Provides a wrapper for managing multicast delegates for handling specific errors
/// </summary>
public struct MulticastExceptionHandler
public readonly struct MulticastExceptionHandler
{
private readonly Dictionary<Type, MulticastDelegate> _handlers;

Expand All @@ -17,9 +17,14 @@ public struct MulticastExceptionHandler
/// </summary>
public MulticastExceptionHandler()
{
_handlers = new Dictionary<Type, MulticastDelegate>();
_handlers = [];
}

/// <summary>
/// Registers a callback to handle the specified exception
/// </summary>
/// <typeparam name="TException">The <see cref="Exception"/> type.</typeparam>
/// <param name="callback">The callback to invoke for the given <see cref="Exception"/> type.</param>
public void Register<TException>(MulticastDelegate callback)
where TException : Exception
{
Expand All @@ -42,6 +47,13 @@ public bool CanHandle(Exception exception) =>
public async void Handle(Exception exception, object? parameter = null) =>
await HandleAsync(exception, parameter);

/// <summary>
/// Handles a specified <see cref="Exception"/> asynchronously with a given optional parameter
/// </summary>
/// <param name="exception">The <see cref="Exception"/> encountered.</param>
/// <param name="parameter">An optional parameter which may be passed to a registered callback delegate.</param>
/// <returns>An asynchronus Task.</returns>
/// <exception cref="InvalidOperationException"></exception>
public async Task HandleAsync(Exception exception, object? parameter = null)
{
var multicastDelegate = GetDelegate(exception.GetType());
Expand Down
20 changes: 20 additions & 0 deletions src/Prism.Core/Mvvm/ViewCreationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,41 @@

namespace Prism.Mvvm;

/// <summary>
/// Exception thrown when an error occurs during view creation.
/// </summary>
public class ViewCreationException : Exception
{
/// <summary>
/// Initializes a new instance of the ViewCreationException class with the specified view name and view type.
/// </summary>
/// <param name="viewName">The name of the view that failed to create.</param>
/// <param name="viewType">The type of view that failed to create (Page, Region, or Dialog).</param>
public ViewCreationException(string viewName, ViewType viewType)
: this(viewName, viewType, null)
{
}

/// <summary>
/// Initializes a new instance of the ViewCreationException class with the specified view name, view type, and inner exception.
/// </summary>
/// <param name="viewName">The name of the view that failed to create.</param>
/// <param name="viewType">The type of view that failed to create (Page, Region, or Dialog).</param>
/// <param name="innerException">The inner exception that caused the view creation to fail.</param>
public ViewCreationException(string viewName, ViewType viewType, Exception innerException)
: base($"Unable to create {viewType} '{viewName}'.", innerException)
{
ViewName = viewName;
ViewType = viewType;
}

/// <summary>
/// Gets the type of view that failed to create (Page, Region, or Dialog).
/// </summary>
public ViewType ViewType { get; }

/// <summary>
/// Gets the name of the view that failed to create.
/// </summary>
public string ViewName { get; }
}
28 changes: 26 additions & 2 deletions src/Prism.Core/Mvvm/ViewModelCreationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,46 @@

namespace Prism.Mvvm;

/// <summary>
/// Exception thrown when an error occurs during ViewModel creation.
/// </summary>
public class ViewModelCreationException : Exception
{
private static Func<object, string> _viewNameDelegate = null;

/// <summary>
/// Gets the name of the view associated with the exception, based on platform-specific logic.
/// </summary>
/// <param name="view">The view instance for which ViewModel creation failed.</param>
/// <returns>The name of the view, or "Platform not initialized" if the platform is not initialized.</returns>
private static string GetViewName(object view) => _viewNameDelegate is null ? "Platform not initialized" : _viewNameDelegate(view);

/// <summary>
/// Sets the delegate used to retrieve view names for exceptions.
/// </summary>
/// <param name="viewNameDelegate">The delegate that retrieves view names.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetViewNameDelegate(Func<object, string> viewNameDelegate) => _viewNameDelegate = viewNameDelegate;

/// <summary>
/// Initializes a new instance of the ViewModelCreationException class with the specified view and inner exception.
/// </summary>
/// <param name="view">The view for which ViewModel creation failed.</param>
/// <param name="innerException">The inner exception that caused the ViewModel creation to fail.</param>
public ViewModelCreationException(object view, Exception innerException)
: base($"Unable to Create ViewModel for '{view.GetType().FullName}'.", innerException)
{
View = view;
ViewName = GetViewName(view);
}

public string ViewName { get; }

/// <summary>
/// Gets the view instance for which ViewModel creation failed.
/// </summary>
public object View { get; }

/// <summary>
/// Gets the name of the view associated with the exception.
/// </summary>
public string ViewName { get; }
}
19 changes: 19 additions & 0 deletions src/Prism.Core/Mvvm/ViewRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,29 @@

namespace Prism.Mvvm;

/// <summary>
/// Represents information about a registered view.
/// </summary>
public record ViewRegistration
{
/// <summary>
/// Gets the type of view this registration represents (Page, Region, or Dialog).
/// </summary>
public ViewType Type { get; init; }

/// <summary>
/// Gets the type of the view class associated with this registration.
/// </summary>
public Type View { get; init; }

/// <summary>
/// Gets the type of the view model associated with this registration, if any.
/// </summary>
public Type ViewModel { get; init; }

/// <summary>
/// Gets the unique name used to identify this view registration.
/// </summary>
public string Name { get; init; }
}

Loading

0 comments on commit ae26f82

Please sign in to comment.