/// <summary> /// Tries to register the value of the specified type for this <see cref="SridItem"/>. The value must be unique in the register /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> public void SetId <T>(T value) where T : struct, Enum { if (Id <T>().HasValue || !SridRegister.TryRegisterId(this, value)) { throw new InvalidOperationException(); } }
/// <summary> /// Gets the registered value of the specified type for this <see cref="SridItem"/>. Users are generally expected to pass their own enum types. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T?Id <T>() where T : struct, Enum { int n = SridRegister.GetIdType <T>(); object v = (n < _idMap.Count) ? _idMap[n] : null; if (v is T t) { return(t); } else { return(null); } }