コード例 #1
0
        public SettingsPropertyDefinitionWrapper(object @object) : base()
        {
            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));
            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));


            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)
                : null;

            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 ?? "";
            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;
        }
    }
}
コード例 #2
0
 set => SetValue(GroupNameProperty, value);
コード例 #3
0
 set => this.SetValue(GroupNameProperty, value);