From af3d3350794d686f2968ff3fd8704297bcdd9d04 Mon Sep 17 00:00:00 2001 From: Austin Noska Date: Wed, 28 Jul 2021 14:23:23 -0400 Subject: [PATCH] feat: Add TryParse overload method to StringUtils, which tries to parse a GUID from a string --- CHANGELOG.md | 2 ++ ICD.Common.Utils/StringUtils.cs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 575d83e..ca2ddf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + - TryParse overload in StringUtils, attempts to parse a GUID from a string ## [15.1.0] - 2021-08-03 ### Added diff --git a/ICD.Common.Utils/StringUtils.cs b/ICD.Common.Utils/StringUtils.cs index 83194b5..e56c0a0 100644 --- a/ICD.Common.Utils/StringUtils.cs +++ b/ICD.Common.Utils/StringUtils.cs @@ -355,6 +355,27 @@ namespace ICD.Common.Utils return TryConvert(Convert.ToBoolean, value, out result); } + /// + /// Attempts to parse the string as a guid. + /// + /// + /// + /// + [PublicAPI] + public static bool TryParse([NotNull] string value, out Guid result) + { + try + { + result = new Guid(value); + return true; + } + catch (Exception) + { + result = Guid.Empty; + return false; + } + } + /// /// Attempts to parse the string via the given conversion function. ///