mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 03:57:32 +00:00
feat: Add TryParse overload method to StringUtils, which tries to parse a GUID from a string
This commit is contained in:
parent
375e3154c6
commit
af3d335079
2 changed files with 23 additions and 0 deletions
|
|
@ -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).
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Added
|
||||||
|
- TryParse overload in StringUtils, attempts to parse a GUID from a string
|
||||||
|
|
||||||
## [15.1.0] - 2021-08-03
|
## [15.1.0] - 2021-08-03
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,27 @@ namespace ICD.Common.Utils
|
||||||
return TryConvert(Convert.ToBoolean, value, out result);
|
return TryConvert(Convert.ToBoolean, value, out result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attempts to parse the string as a guid.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <param name="result"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to parse the string via the given conversion function.
|
/// Attempts to parse the string via the given conversion function.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue