public static KeyRange Parse(string str) { Contracts.AssertValue(str); var res = new KeyRange(); if (res.TryParse(str)) { return(res); } return(null); }
/// <summary> /// Attempt to parse the string into a data kind and (optionally) a key range. This method does not check whether /// the returned <see cref="DataKind"/> can really be made into a key with the specified <paramref name="keyRange"/>. /// </summary> /// <param name="str">The string to parse.</param> /// <param name="dataKind">The parsed data kind.</param> /// <param name="keyRange">The parsed key range, or null if there's no key specification.</param> /// <returns>Whether the parsing succeeded or not.</returns> public static bool TryParseDataKind(string str, out DataKind dataKind, out KeyRange keyRange) { Contracts.CheckValue(str, nameof(str)); keyRange = null; dataKind = default(DataKind); int ich = str.IndexOf('['); if (ich >= 0) { if (str[str.Length - 1] != ']') { return(false); } keyRange = KeyRange.Parse(str.Substring(ich + 1, str.Length - ich - 2)); if (keyRange == null) { return(false); } if (ich == 0) { return(true); } str = str.Substring(0, ich); } DataKind kind; if (!Enum.TryParse <DataKind>(str, true, out kind)) { return(false); } dataKind = kind; return(true); }