-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathConvertUtil.cs
39 lines (35 loc) · 1.14 KB
/
ConvertUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics;
using System.Globalization;
#nullable disable
namespace Microsoft.Build.Tasks.Deployment.ManifestUtilities
{
internal static class ConvertUtil
{
public static bool ToBoolean(string value)
{
return ToBoolean(value, false);
}
public static bool ToBoolean(string value, bool defaultValue)
{
if (!String.IsNullOrEmpty(value))
{
try
{
return Convert.ToBoolean(value, CultureInfo.InvariantCulture);
}
catch (FormatException)
{
Debug.Fail($"Invalid value '{value}' for {typeof(bool).Name}, returning {defaultValue}");
}
catch (ArgumentException)
{
Debug.Fail($"Invalid value '{value}' for {typeof(bool).Name}, returning {defaultValue}");
}
}
return defaultValue;
}
}
}