StringReference Class

Summary

A string wrapper which allows fast reference equality checks and dictionary usage by ensuring that users of identical strings are given the same Animancer.StringReference instead of needing to compare each character in the strings.
Assembly
Animancer.dll
Namespace
Animancer
Interfaces
Base Types
  • Object
graph BT Type-->Base0["Object"] Type-.->Interface0["IComparable<StringReference>"] Type-.->Interface1["IConvertable<string>"] Type["StringReference"] class Type type-node

Syntax

public class StringReference : IComparable<StringReference>, IConvertable<string>

Remarks

Rather than a constructor, instances of this class are acquired via Animancer.StringReference.Get(System.String) or via implicit conversion from string (which calls the same method).

Unlike UnityEngine.InputSystem.Utilities.InternedString, this implementation is case-sensitive and treats null and "" as not equal. It's also a class to allow usage as a key in a dictionary keyed by System.Object without boxing.

Example:
public static readonly StringReference MyStringReference = "My String";

Fields

Name Constant Value Summary
String
The encapsulated string.

Methods

Name Value Summary
CompareTo(StringReference) int
Compares the Animancer.StringReference.Strings.
Get(string) StringReference
Returns a Animancer.StringReference containing the `value`.
static
Get(string[]) StringReference[]
Creates a new array of Animancer.StringReferences to the `strings`.
static
ToString() string
Returns the Animancer.StringReference.String.
TryGet(string, StringReference) bool
Returns a Animancer.StringReference containing the `value` if one has already been created.
static

Operators

Name Value Summary
implicit operator string(StringReference) string
implicit operator StringReference(string) StringReference

Extension Methods

Name Value Summary
EqualsWhereEmptyIsNull(StringReference) bool
Is the Animancer.StringReference.String equal to the `other` when treating "" as equal to null?
IsNullOrEmpty() bool
Is the `reference` null or its Animancer.StringReference.String empty?