/// <summary> /// Sets value for given field. /// </summary> /// <typeparam name="T">Type of field</typeparam> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns>The value.</returns> public T Set <T>(WebSocketField <T> field, T value) { lock (_L_fields) { _fields[field] = value; return(value); } }
/// <summary> /// Initialize field with given initialization value value. If field already contains a value, initializationValue is not used. /// </summary> /// <typeparam name="T">Type of field</typeparam> /// <param name="field">The field.</param> /// <param name="initializationValue">The value.</param> /// <returns><c>true</c> if initalization was used, <c>false</c> otherwise</returns> public bool Initialize <T>(WebSocketField <T> field, T initializationValue) { if (_fields.ContainsKey(field)) { return(false); } _fields[field] = initializationValue; return(true); }
/// <summary> /// Gets value stored for given field. /// </summary> /// <typeparam name="T">Type of field</typeparam> /// <param name="field">The field.</param> /// <returns>The value.</returns> public T Get <T>(WebSocketField <T> field) { lock (_L_fields) { if (!_fields.TryGetValue(field, out object fieldValue)) { //because of default we have to check the field presence return(default(T)); } return((T)fieldValue); } }