MonkeyModdingTroop / MonkeyLoader

A convenience and extendability focused mod loader using NuGet packages.
https://monkeymoddingtroop.github.io/MonkeyLoader/index.html
GNU Lesser General Public License v3.0
11 stars 3 forks source link

Add `implicit operator T` to `DefiningConfigKey<T>` that allows you to more easily get the value from it #23

Closed Nytra closed 2 weeks ago

Nytra commented 1 month ago
public static implicit operator T(DefiningConfigKey<T> key)
{
    return key.GetValue();
}

So for example, the following code would work:

DefiningConfigKey<bool> boolKey = new("Bool Key ID", "Bool Key Description", () => false);

// boolKey implictly calls GetValue() and returns the value.
if (boolKey) {
    // ...
}

This is the same thing that Sync<T> does to let you get the value without needing to actually use the Value property every time.