public void NumericUtility_TryParseUInt32_1() { uint value; Assert.IsTrue(NumericUtility.TryParseUInt32("123", out value)); Assert.AreEqual(123u, value); Assert.IsFalse(NumericUtility.TryParseUInt32("hello", out value)); Assert.IsFalse(NumericUtility.TryParseUInt32(string.Empty, out value)); Assert.IsFalse(NumericUtility.TryParseUInt32(null, out value)); }
public static uint GetUInt32 ( [NotNull] string key, uint defaultValue = 0 ) { string setting = CM.AppSettings[key]; if (!NumericUtility.TryParseUInt32(setting, out uint result)) { result = defaultValue; } return(result); }
public static uint GetUInt32 ( [NotNull] string key, uint defaultValue ) { #if DROID || ANDROID || UAP return(defaultValue); #else uint result; string s = CM.AppSettings[key]; if (!NumericUtility.TryParseUInt32(s, out result)) { result = defaultValue; } return(result); #endif }
/// <summary> /// Parse the text. /// </summary> public static RepeatSpecification Parse ( [NotNull] string text ) { Sure.NotNullNorEmpty(text, nameof(text)); RepeatSpecification result = new RepeatSpecification(); switch (text) { case "*": result.Kind = RepeatKind.All; break; case "F": result.Kind = RepeatKind.ByFormat; break; case "L": result.Kind = RepeatKind.Last; break; default: if (NumericUtility.TryParseUInt32(text, out uint index)) { if (index == 0) { throw new IrbisException ( "Invalid repeat specification: " + text ); } result.Kind = RepeatKind.Explicit; result.Index = (int)index; } else if (text[0] == 'L' && NumericUtility.TryParseUInt32 ( text.Substring(2), out index )) { result.Kind = RepeatKind.Last; result.Index = (int)index; } else { Log.Error ( "RepeatSpecification::Parse: " + "invalid repeat specification=" + text ); throw new IrbisException ( "Invalid repeat specification: " + text ); } break; } return(result); }