mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-28 01:25:44 -05:00
fixed an issue with setting a boolean option to string (#291)
* fixed an issue with setting an option which Boolean to string
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Microsoft.SqlTools.Utility;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
{
|
||||
@@ -446,11 +449,27 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
|
||||
if (Options != null && Options.ContainsKey(name))
|
||||
{
|
||||
object value = Options[name];
|
||||
if(value != null && ( typeof(T) == typeof(int) || typeof(T) == typeof(int?)))
|
||||
try
|
||||
{
|
||||
value = System.Convert.ToInt32(value);
|
||||
if (value != null && (typeof(T) != value.GetType()))
|
||||
{
|
||||
if (typeof(T) == typeof(int) || typeof(T) == typeof(int?))
|
||||
{
|
||||
value = Convert.ToInt32(value);
|
||||
}
|
||||
else if (typeof(T) == typeof(bool) || typeof(T) == typeof(bool?))
|
||||
{
|
||||
value = Convert.ToBoolean(value);
|
||||
}
|
||||
}
|
||||
result = value != null ? (T)value : default(T);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = default(T);
|
||||
Logger.Write(LogLevel.Warning, string.Format(CultureInfo.InvariantCulture,
|
||||
"Cannot convert option value {0}:{1} to {2}", name, value ?? "", typeof(T)));
|
||||
}
|
||||
result = value != null ? (T)value : default(T);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user