IPersistentField Interface |
Namespace: KSPDev.ConfigUtils
The IPersistentField type exposes the following members.
Name | Description | |
---|---|---|
![]() | ParseFromString | Restores the object's state from a plain string. |
![]() | SerializeToString | Returns the object's state as a plain string. |
Note that the types that implement this interface will never be treated as compound. I.e. ConfigAccessor will not try to persist the members of such types even though there may be fields attributed with PersistentFieldAttribute.
public class MyVector : IPeristentField { float x; float y; /// <inheritdoc/> public string SerializeToString() { return string.Format("{0},{1}", x ,y); } /// <inheritdoc/> public void ParseFromString(string value) { var elements = value.Split(','); x = float.Parse(elements[0]); y = float.Parse(elements[1]); } }
This example doesn't do any checking when parsing the string, but in general it's a good idea to do a sanity check of the string. It's OK to throw an exception from the parsing method when the data is invalid.