< Summary

Information
Class: MyNet.UI.Locators.ViewResolutionException
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Locators/ViewResolutionException.cs
Tag: 323_28699572109
Line coverage
53%
Covered lines: 14
Uncovered lines: 12
Coverable lines: 26
Total lines: 93
Line coverage: 53.8%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%210%
.ctor(...)100%210%
.ctor(...)100%210%
.ctor(...)100%11100%
NoMapping(...)100%11100%
CannotInstantiateView(...)100%210%
ResolvedViewTypeMismatch(...)100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Locators/ViewResolutionException.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="ViewResolutionException.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8
 9namespace MyNet.UI.Locators;
 10
 11/// <summary>
 12/// Thrown when a view cannot be resolved from a view model type or instantiated.
 13/// </summary>
 14public sealed class ViewResolutionException : InvalidOperationException
 15{
 16    /// <summary>
 17    /// Initializes a new instance of the <see cref="ViewResolutionException"/> class.
 18    /// </summary>
 19    public ViewResolutionException()
 020        : this("View resolution failed.", null, null, null)
 21    {
 022    }
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="ViewResolutionException"/> class with a message.
 26    /// </summary>
 27    /// <param name="message">The error message.</param>
 28    public ViewResolutionException(string message)
 029        : this(message, null, null, null)
 30    {
 031    }
 32
 33    /// <summary>
 34    /// Initializes a new instance of the <see cref="ViewResolutionException"/> class with a message and inner exception
 35    /// </summary>
 36    /// <param name="message">The error message.</param>
 37    /// <param name="innerException">The inner exception.</param>
 38    public ViewResolutionException(string message, Exception innerException)
 039        : this(message, null, null, innerException)
 40    {
 041    }
 42
 43    /// <summary>
 44    /// Gets the view model type involved in the failure, when applicable.
 45    /// </summary>
 46    public Type? ViewModelType { get; }
 47
 48    /// <summary>
 49    /// Gets the view type involved in the failure, when applicable.
 50    /// </summary>
 51    public Type? ViewType { get; }
 52
 53    private ViewResolutionException(string message, Type? viewModelType, Type? viewType, Exception? innerException)
 654        : base(message, innerException)
 55    {
 56        ViewModelType = viewModelType;
 57        ViewType = viewType;
 658    }
 59
 60    /// <summary>
 61    /// Creates an exception when no view type mapping exists for a view model.
 62    /// </summary>
 63    public static ViewResolutionException NoMapping(Type viewModelType) =>
 364        new(
 365            $"No view type mapping found for view model '{viewModelType.FullName}'. " +
 366            "Register a manual mapping via ITypeResolver.Register or add a naming convention.",
 367            viewModelType,
 368            null,
 369            null);
 70
 71    /// <summary>
 72    /// Creates an exception when a view type cannot be instantiated.
 73    /// </summary>
 74    public static ViewResolutionException CannotInstantiateView(Type viewType, Exception? innerException = null) =>
 075        new(
 076            $"Cannot create an instance of view '{viewType.FullName}'. " +
 077            "Register the view in DI or provide a public parameterless constructor.",
 078            null,
 079            viewType,
 080            innerException);
 81
 82    /// <summary>
 83    /// Creates an exception when the resolved view instance is not assignable to the expected type.
 84    /// </summary>
 85    public static ViewResolutionException ResolvedViewTypeMismatch(Type viewModelType, Type resolvedViewType, Type expec
 386        new(
 387            $"View resolved for '{viewModelType.FullName}' is '{resolvedViewType.FullName}', " +
 388            $"but '{expectedViewType.FullName}' was expected.",
 389            viewModelType,
 390            resolvedViewType,
 391            null);
 92}
 93