/// <summary> /// Attempt to parse a string as a version. /// </summary> /// <param name="versionStr">The string to parse.</param> /// <param name="version">The parsed version, if successful.</param> /// <returns>True if the string was successfully parsed, false otherwise.</returns> public static bool TryParse(string versionStr, out PowerShellVersion version) { try { version = Parse(versionStr); return(true); } catch { version = null; return(false); } }
/// <summary> /// Read a PowerShellVersion object from a JSON string representing a version. /// </summary> /// <param name="reader"></param> /// <param name="objectType"></param> /// <param name="existingValue"></param> /// <param name="serializer"></param> /// <returns></returns> public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { string s = (string)reader.Value; if (s == null) { return(null); } if (objectType == typeof(Version)) { return((Version)PowerShellVersion.Parse(s)); } return(PowerShellVersion.Parse(s)); }