Wiki > SerializableDictionary

IDAttribute class

Attribute class that can be used to sync the dictionary key with a field value. This will make the field value to be changed when the entry key is changed.

Namespace: RotaryHeart.Lib.SerializableDictionary
Package: Serializable Dictionary


public class IDAttribute : System.Attribute


Accessibility Level Name Description
public IDAttribute(string) Serializable field name for the property id.


Accessibility Level Type Name Description
public string Id Returns the field name passed on the contructor.


Here's a quick example of how to use the attribute. Let's say that we have a generic class that we want to use as the dictionary value and a string as the key. For that we need to create our value class, called ClassTest, and our dictionary, called GenericDictionary.

If we want to sync the class field id with the dictionary key (so that everytime the key is changed on the inspector the value is saved on our class) all we need to do is add the attribute ID to our dictionary field and specify the name of the field that we want to sync. Note that this code is part of the DataBaseExample class provided on the package.

public class ClassTest
    public string id;
    public float test;
    public string test2;
    public Quaternion quat;
    public ChildTest[] childTest;

public class GenericDictionary : SerializableDictionaryBase<string, ClassTest> { }

[SerializeField, ID("id")]
private GenericDictionary _generic;

With this code every time an entry key value is changed, it will be saved on the value id field too.