PersistentFieldsFileAttribute Class |
Namespace: KSPDev.ConfigUtils
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct, AllowMultiple = true)] public sealed class PersistentFieldsFileAttribute : AbstractPersistentFieldsFileAttribute
The PersistentFieldsFileAttribute type exposes the following members.
Name | Description | |
---|---|---|
![]() | PersistentFieldsFileAttribute | Constructor for a persistent field. |
This assignment is ignored in the nested classes. Though, when using nested class as an immediate target of the call the annotation will be handled just fine.
[PersistentFieldsFile("settings.cfg", "Root/Default")] [PersistentFieldsFile("settings-other.cfg", "", "abc")] [PersistentFieldsFile("settings-nested-bad.cfg", "", "nevermind")] class ClassWithPersistentFields { [PersistentField("field1")] private int intField = 0; [PersistentFieldsFile("settings-nested-good.cfg", "Root/Nested", "nevermind")] internal struct ComplexType { [PersistentField("val1", group = "nevermind")] public bool boolVal; [PersistentField("val2", group = "nevermind")] public Color colorVal; } [PersistentField("complexField1", group = "abc")] private ComplexType complexField; void SaveFields() { // Save a default group of fields. ConfigAccessor.WriteFieldsFromType(instance: this); /* File will be created at "GameData/settings.cfg": * Root * { * Default * { * field1: 0 * } * } */ // Save group "abc". Note that the complex type only defines fields for group "nevermind" // but it's ignored. The group is only honored on the immediate type, i.e. // ClassWithPersistentFields in this case. ConfigAccessor.WriteFieldsFromType(instance: this, group: "abc"); /* File will be created at "GameData/settings-other.cfg". * { * complexField1 * { * val1: False * val2: 0,0,0,1 * } * } */ // Try to use incorrect setup and save group "nevermind" for "this". // File will be created at "GameData/settings-nested-bad.cfg". And it will be empty since // no fields for this group is defined in class ClassWithPersistentFields. ConfigAccessor.WriteFieldsFromType(instance: this, group: "nevermind"); // Proper use of the nested complex type would be like this. var test = new ComplexType() { boolVal = true, colorVal = Color.white }; ConfigAccessor.WriteFieldsFromType(instance: test, group: "nevermind"); /* File will be created at "GameData/settings-nested-good.cfg". * Root * { * Nested * { * complexField1 * { * val1: True * val2: 1,1,1,1 * } * } * } */ // The following call makes the similar output but with different values. ConfigAccessor.WriteFieldsFromType(instance: complexField, group: "nevermind"); } }