public void TryGetWorks() { var setting = new ScalableSetting <int>(new[] { 1, 2, 3 }, ScalableSettingSchemaId.With3Levels); Assert.True(setting.TryGet(0, out var v)); Assert.AreEqual(1, v); Assert.False(setting.TryGet(-1, out v)); Assert.AreEqual(default(int), v); Assert.True(setting.TryGet(2, out v)); Assert.AreEqual(3, v); Assert.False(setting.TryGet(3, out v)); Assert.AreEqual(default(int), v); }
/// <summary> /// Evaluate the value of the scalable setting value. /// </summary> /// <typeparam name="T">The type of the scalable setting.</typeparam> /// <param name="setting">The scalable setting to use to evaluate levels.</param> /// <param name="value">The evaluated value.</param> /// <returns><c>true</c> when the value was evaluated, <c>false</c> when the value could not be evaluated.</returns> public bool TryGetValue <T>(ScalableSetting <T> setting, out T value) where T : struct { if (hasMultipleValues) { value = default; return(false); } if (useOverride.boolValue) { value = @override.GetInline <T>(); return(true); } else { var actualLevel = level.intValue; return(setting.TryGet(actualLevel, out value)); } }