Aragas/Bannerlord.MBOptionScreen

View on GitHub
src/MCM.UI/GUI/ViewModels/SettingsPropertyVM.String.cs

Summary

Maintainability
A
0 mins
Test Coverage
using MCM.Abstractions;
using MCM.UI.Actions;

using TaleWorlds.Library;

namespace MCM.UI.GUI.ViewModels
{
    internal sealed partial class SettingsPropertyVM : ViewModel
    {
        [DataSourceProperty]
        public bool IsString => SettingType == SettingType.String;

        [DataSourceProperty]
        public string StringValue
        {
            get => IsString ? PropertyReference.Value is null ? string.Empty : PropertyReference.Value is string val ? val : "ERROR" : string.Empty;
            set
            {
                if (IsString && StringValue != value)
                {
                    URS.Do(new SetStringAction(PropertyReference, value));
                    OnPropertyChanged(nameof(StringValue));
                }
            }
        }
    }
}