Esempio n. 1
0
        public SettingsPropertyDefinitionWrapper(object @object)
        {
            var type = @object.GetType();

            SettingsIdProperty       = AccessTools.Property(type, nameof(SettingsId));
            SettingTypeProperty      = AccessTools.Property(type, nameof(SettingType));
            PropertyProperty         = AccessTools.Property(type, nameof(PropertyReference));
            DisplayNameProperty      = AccessTools.Property(type, nameof(DisplayName));
            HintTextProperty         = AccessTools.Property(type, nameof(HintText));
            OrderProperty            = AccessTools.Property(type, nameof(Order));
            RequireRestartProperty   = AccessTools.Property(type, nameof(RequireRestart));
            GroupNameProperty        = AccessTools.Property(type, nameof(GroupName));
            GroupOrderProperty       = AccessTools.Property(type, nameof(GroupOrder));
            IsMainToggleProperty     = AccessTools.Property(type, nameof(IsMainToggle));
            MinValueProperty         = AccessTools.Property(type, nameof(MinValue));
            MaxValueProperty         = AccessTools.Property(type, nameof(MaxValue));
            EditableMinValueProperty = AccessTools.Property(type, nameof(EditableMinValue));
            EditableMaxValueProperty = AccessTools.Property(type, nameof(EditableMaxValue));
            SelectedIndexProperty    = AccessTools.Property(type, nameof(SelectedIndex));
            ValueFormatProperty      = AccessTools.Property(type, nameof(ValueFormat));
            CustomFormatterProperty  = AccessTools.Property(type, nameof(CustomFormatter));


            SettingsId  = SettingsIdProperty?.GetValue(@object) as string ?? "ERROR";
            SettingType = SettingTypeProperty?.GetValue(@object) is { } settingTypeObject
                ? Enum.TryParse <SettingType>(settingTypeObject.ToString(), out var resultEnum)
                    ? resultEnum
                    : SettingType.NONE
                : SettingType.NONE;

            PropertyReference = PropertyProperty?.GetValue(@object) is { } value
                ? value is IRef @ref ? @ref : new RefWrapper(value)
                : new ProxyRef <object?>(() => null, o => { });

            DisplayName = DisplayNameProperty?.GetValue(@object) switch
            {
                string str => str,
                TextObject to => to.ToString(),
                       _ => DisplayName
            };
            HintText = HintTextProperty?.GetValue(@object) switch
            {
                string str => str,
                TextObject to => to.ToString(),
                       _ => HintText
            };
            Order          = OrderProperty?.GetValue(@object) as int? ?? -1;
            RequireRestart = RequireRestartProperty?.GetValue(@object) as bool? ?? true;

            GroupName    = GroupNameProperty?.GetValue(@object) as string ?? "";
            GroupOrder   = GroupOrderProperty?.GetValue(@object) as int? ?? -1;
            IsMainToggle = IsMainToggleProperty?.GetValue(@object) as bool? ?? false;

            MinValue         = MinValueProperty?.GetValue(@object) is { } minVal?minVal as decimal? ?? 0 : 0;
            MaxValue         = MaxValueProperty?.GetValue(@object) is { } maxVal?maxVal as decimal? ?? 0 : 0;
            EditableMinValue = EditableMinValueProperty?.GetValue(@object) is { } eMinVal?  eMinVal as decimal? ?? 0 : 0;
            EditableMaxValue = EditableMaxValueProperty?.GetValue(@object) is { } eMaxValue?eMaxValue as decimal? ?? 0 : 0;

            SelectedIndex = SelectedIndexProperty?.GetValue(@object) as int? ?? 0;

            ValueFormat = ValueFormatProperty?.GetValue(@object) as string ?? SettingType switch
            {
                SettingType.Int => "0",
                SettingType.Float => "0.00",
                _ => ""
            };
            CustomFormatter = CustomFormatterProperty?.GetValue(@object) as Type;
        }
    }
}
Esempio n. 2
0
 set => SetValue(ValueFormatProperty, value);