[+] Add some interfaces for attributes

This commit is contained in:
Clansty
2024-11-26 00:03:35 +08:00
parent 0ec048ceba
commit 792dce6843
9 changed files with 38 additions and 9 deletions

View File

@@ -1,8 +1,9 @@
using System;
using AquaMai.Config.Interfaces;
namespace AquaMai.Config.Attributes;
public record ConfigComment(string CommentEn, string CommentZh)
public record ConfigComment(string CommentEn, string CommentZh) : IConfigComment
{
public string GetLocalized(string lang) => lang switch
{

View File

@@ -1,4 +1,5 @@
using System;
using AquaMai.Config.Interfaces;
namespace AquaMai.Config.Attributes;
@@ -16,9 +17,9 @@ public class ConfigEntryAttribute(
// Only use it to hide options that really won't be used.
bool hideWhenDefault = false,
// NOTE: Use this argument to mark special config entries that need special handling.
SpecialConfigEntry specialConfigEntry = SpecialConfigEntry.None) : Attribute
SpecialConfigEntry specialConfigEntry = SpecialConfigEntry.None) : Attribute, IConfigEntryAttribute
{
public ConfigComment Comment { get; } = new ConfigComment(en, zh);
public IConfigComment Comment { get; } = new ConfigComment(en, zh);
public bool HideWhenDefault { get; } = hideWhenDefault;
public SpecialConfigEntry SpecialConfigEntry { get; } = specialConfigEntry;
}

View File

@@ -1,4 +1,5 @@
using System;
using AquaMai.Config.Interfaces;
namespace AquaMai.Config.Attributes;
@@ -12,9 +13,9 @@ public class ConfigSectionAttribute(
bool defaultOn = false,
// NOTE: You probably shouldn't use this. Only the "General" section is using this.
// Implies defaultOn = true.
bool alwaysEnabled = false) : Attribute
bool alwaysEnabled = false) : Attribute, IConfigSectionAttribute
{
public ConfigComment Comment { get; } = new ConfigComment(en, zh);
public IConfigComment Comment { get; } = new ConfigComment(en, zh);
public bool ExampleHidden { get; } = exampleHidden;
public bool DefaultOn { get; } = defaultOn || alwaysEnabled;
public bool AlwaysEnabled { get; } = alwaysEnabled;