Click or drag to resize

MessageLookupTLookup Method

Finds and returns a message for the provided key.

Namespace:  KSPDev.GUIUtils
Assembly:  KSPDev_Utils.2.0 (in KSPDev_Utils.2.0.dll) Version: 2.0 for KSP v1.8+
Syntax
C#
public Message Lookup(
	T key
)
Request Example View Source

Parameters

key
Type: T
The key to find a message for.

Return Value

Type: Message
The relevant message if the key is found. Otherwise, either the defaultMessage or a string represenation of the key. It's never null.
Examples
public class MessageLookupDemo2 : PartModule {
  enum MyEnum {
    One,
    Two,
    Three,
  }

  // Create the messages separately from the lookup to allow the LocalizationTool to pick them up.
  static readonly Message msg_1 = new Message("#msg1", defaultTemplate: "-ONE-");
  static readonly Message defMsg = new Message("#def", defaultTemplate: "-DEFAULT-");

  static readonly MessageLookup<MyEnum> msg = new MessageLookup<MyEnum>(
      new Dictionary<MyEnum, Message>() {
          {MyEnum.One, msg_1},
      }, defaultMessage: defMsg);

  void Show() {
    Debug.Log(msg.Lookup(MyEnum.One));
    // Prints: "-ONE-"
    Debug.Log(msg.Lookup(MyEnum.Two));
    // Prints: "-DEFAULT-"
    Debug.Log(msg.Lookup(MyEnum.Three));
    // Prints: "-DEFAULT-"
  }
}
Examples
public class MessageLookupDemo3 : PartModule {
  enum MyEnum {
    One,
    Two,
    Three,
  }

  // Create the messages separately from the lookup to allow the LocalizationTool to pick them up.
  static readonly Message msg_1 = new Message("#msg1", defaultTemplate: "-ONE-");

  static readonly MessageLookup<MyEnum> msg = new MessageLookup<MyEnum>(
      new Dictionary<MyEnum, Message>() {
          {MyEnum.One, msg_1},
      });

  void Show() {
    Debug.Log(msg.Lookup(MyEnum.One));
    // Prints: "-ONE-"
    Debug.Log(msg.Lookup(MyEnum.Two));
    // Prints: "Two"
  }
}
See Also