Working with warnings
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user