Aragas/Bannerlord.MBOptionScreen

View on GitHub
src/MCM.Abstractions/Definitions/Wrapper/BasePropertyDefinitionWrapper.cs

Summary

Maintainability
A
0 mins
Test Coverage

namespace MCM.Abstractions.Wrapper
{
#if !BANNERLORDMCM_INCLUDE_IN_CODE_COVERAGE
    [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage, global::System.Diagnostics.DebuggerNonUserCode]
#endif
#if !BANNERLORDMCM_PUBLIC
    internal
#else
    public
# endif
    abstract class BasePropertyDefinitionWrapper : IPropertyDefinitionBase
    {
        /// <inheritdoc/>
        public string DisplayName { get; }
        /// <inheritdoc/>
        public int Order { get; }
        /// <inheritdoc/>
        public bool RequireRestart { get; }
        /// <inheritdoc/>
        public string HintText { get; }

        protected BasePropertyDefinitionWrapper(object @object)
        {
            var type = @object.GetType();

            DisplayName = type.GetProperty(nameof(DisplayName))?.GetValue(@object) as string ?? "ERROR";
            Order = type.GetProperty(nameof(Order))?.GetValue(@object) as int? ?? -1;
            RequireRestart = type.GetProperty(nameof(RequireRestart))?.GetValue(@object) as bool? ?? true;
            HintText = type.GetProperty(nameof(HintText))?.GetValue(@object) as string ?? "ERROR";
        }
    }
}