mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Did something similar for NHSE years ago. Allows for much easier reuse elsewhere and clearer usage.
24 lines
847 B
C#
24 lines
847 B
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Default property provider that uses an <see cref="IBatchEditor{TObject}"/> for reflection.
|
|
/// </summary>
|
|
public class BatchPropertyProvider<TEditor, TObject>(TEditor editor) : IPropertyProvider<TObject> where TObject : notnull where TEditor : IBatchEditor<TObject>
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="BatchPropertyProvider{TEditor, TObject}"/> class with the specified editor.
|
|
/// </summary>
|
|
public bool TryGetProperty(TObject obj, string prop, [NotNullWhen(true)] out string? result)
|
|
{
|
|
result = null;
|
|
if (!editor.TryGetHasProperty(obj, prop, out var pi))
|
|
return false;
|
|
|
|
var value = pi.GetValue(obj);
|
|
result = value?.ToString();
|
|
return result is not null;
|
|
}
|
|
}
|