< Summary

Information
Class: LOCKnet.App.ViewLocator
Assembly: LOCKnet.App
File(s): /home/runner/work/LOCKnet/LOCKnet/src/LOCKnet.App/ViewLocator.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 37
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Build(...)100%44100%
Match(...)100%11100%

File(s)

/home/runner/work/LOCKnet/LOCKnet/src/LOCKnet.App/ViewLocator.cs

#LineLine coverage
 1using Avalonia.Controls;
 2using Avalonia.Controls.Templates;
 3using LOCKnet.App.ViewModels;
 4using System;
 5using System.Diagnostics.CodeAnalysis;
 6
 7namespace LOCKnet.App;
 8
 9/// <summary>
 10/// Given a view model, returns the corresponding view if possible.
 11/// </summary>
 12[RequiresUnreferencedCode(
 13  "Default implementation of ViewLocator involves reflection which may be trimmed away.",
 14  Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
 15public class ViewLocator : IDataTemplate
 16{
 17  public Control? Build(object? param)
 318  {
 319    if (param is null)
 120      return null;
 21
 222    var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
 223    var type = Type.GetType(name);
 24
 225    if (type != null)
 126    {
 127      return (Control)Activator.CreateInstance(type)!;
 28    }
 29
 130    return new TextBlock { Text = "Not Found: " + name };
 331  }
 32
 33  public bool Match(object? data)
 234  {
 235    return data is ViewModelBase;
 236  }
 37}