Working with warnings

This commit is contained in:
Matthias Heil
2026-04-04 15:36:30 +02:00
parent 3b9d8f4c16
commit 015d7d4542
21 changed files with 211 additions and 159 deletions
@@ -2,15 +2,24 @@ using Avalonia.Controls;
using Avalonia.Controls.Templates;
using AvaloniaSerilogDI.ViewModels;
using System;
using System.Diagnostics.CodeAnalysis;
namespace AvaloniaSerilogDI;
// <summary>
/// Given a view model, returns the corresponding view if possible.
/// </summary>
[RequiresUnreferencedCode(
"Default implementation of ViewLocator involves reflection which may be trimmed away.",
Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")]
public class ViewLocator : IDataTemplate
{
public IControl Build(object data)
public Control? Build(object? param)
{
string name = data.GetType().FullName!.Replace("ViewModel", "View");
Type? type = Type.GetType(name);
if (param is null)
return null;
var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
var type = Type.GetType(name);
if (type != null)
{
@@ -20,8 +29,8 @@ public class ViewLocator : IDataTemplate
return new TextBlock { Text = "Not Found: " + name };
}
public bool Match(object data)
public bool Match(object? data)
{
return data is ViewModelBase;
}
}
}