Click or drag to resize

AbstractOrdinaryValueTypeProto Class

A base class for a proto of a single value.
Inheritance Hierarchy

Namespace:  KSPDev.ConfigUtils
Assembly:  KSPDev_Utils.1.2 (in KSPDev_Utils.1.2.dll) Version: 1.2 for KSP v1.6+
Syntax
C#
public abstract class AbstractOrdinaryValueTypeProto
Request Example View Source

The AbstractOrdinaryValueTypeProto type exposes the following members.

Constructors
  NameDescription
Protected methodAbstractOrdinaryValueTypeProto
Default constructor must be the only constructor of the proto.
Top
Methods
  NameDescription
Public methodCanHandle
Tells if proto can handle the specified type.
Public methodParseFromString
Makes a value from the string representation.
Public methodSerializeToString
Serializes value into a string.
Top
Remarks
All descendands of this class must implement a default constructor.
Examples
See real overrides in PrimitiveTypesProto and KspTypesProto.

Here is how you could implement your own proto to persist string array as a string.

class StringArrayProto : AbstractOrdinaryValueTypeProto {
  public override bool CanHandle(Type type) {
    return typeof(string[]) == type;
  }
  public override string SerializeToString(object value) {
    return string.Join(",", (value as string[]));
  }
  public override object ParseFromString(string value, Type type) {
    // Due to check in CanHandle we know the type is string[].
    return value.Split(',');
  }
}
See Also