-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 4030: [5.1.2] Fix | Adding type convertor support for SqlCo…
- Loading branch information
1 parent
80d1f47
commit 0b51b63
Showing
7 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...rosoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionEncryptOptionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
using System; | ||
using System.ComponentModel; | ||
using System.Globalization; | ||
using Microsoft.Data.Common; | ||
|
||
namespace Microsoft.Data.SqlClient | ||
{ | ||
internal class SqlConnectionEncryptOptionConverter : TypeConverter | ||
{ | ||
// Overrides the CanConvertFrom method of TypeConverter. | ||
// The ITypeDescriptorContext interface provides the context for the | ||
// conversion. Typically, this interface is used at design time to | ||
// provide information about the design-time container. | ||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
if (sourceType == typeof(string)) | ||
{ | ||
return true; | ||
} | ||
return base.CanConvertFrom(context, sourceType); | ||
} | ||
|
||
// Overrides the CanConvertTo method of TypeConverter. | ||
public override bool CanConvertTo(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
if (sourceType == typeof(string)) | ||
{ | ||
return true; | ||
} | ||
return base.CanConvertTo(context, sourceType); | ||
} | ||
|
||
// Overrides the ConvertFrom method of TypeConverter. | ||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
if (value is string) | ||
{ | ||
return SqlConnectionEncryptOption.Parse(value.ToString()); | ||
} | ||
throw ADP.ConvertFailed(value.GetType(), typeof(SqlConnectionEncryptOption), null); | ||
} | ||
|
||
// Overrides the ConvertTo method of TypeConverter. | ||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
{ | ||
if (destinationType == typeof(string)) | ||
{ | ||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
throw ADP.ConvertFailed(value.GetType(), typeof(SqlConnectionEncryptOption), null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters