aboutsummaryrefslogtreecommitdiffstats
path: root/QtVsTools.Core/Common/SettingsAttribute.cs
blob: dbdff1d247c6d1c0bddeb9d70ef5c85800dc49cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

using System;

namespace QtVsTools.Core.Common
{
    using QtVsTools.Common;

    public sealed class SettingsAttribute : Attribute
    {
        public SettingsAttribute(string key, object defaultValue)
        {
            DefaultValue = defaultValue;
            Key = key;
        }

        public SettingsAttribute(object key, object defaultValue)
        {
            DefaultValue = defaultValue;
            if (key.GetType().BaseType != typeof(Enum))
                throw new ArgumentException("The provided argument must be an Enum type.");
            Key = ((Enum)key).Cast<string>();
        }

        public string Key { get; }
        public object DefaultValue { get; }
    }
}