forked from dotnet/SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SqlConnectionEncryptOptionConverter class which is used to conver…
…t string Encrypt option into SqlConnectionEncryptionOption type.
- Loading branch information
Showing
8 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
doc/snippets/Microsoft.Data.SqlClient/SqlConnectionEncryptOptionConverter.xml
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,51 @@ | ||
<?xml version="1.0"?> | ||
<docs> | ||
<members name="SqlConnectionEncryptOptionConverter"> | ||
<SqlConnectionEncryptOption> | ||
<summary>Converts a string Sql Connection Encrypt option into SqlConnectionEncryptOption object</summary> | ||
<remarks> | ||
<para> | ||
## Remarks | ||
Implicit conversions have been added to maintain backwards compatibility with boolean behahavior for the <see cref="Microsoft.Data.SqlClient.SqlConnectionStringBuilder.Encrypt" /> property. When converting from a boolean, a value of `true` converts to <see cref="Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory" /> and a value of `false` converts to <see cref="Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional"/>. When converting to a boolean, <see cref="Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Mandatory"/>, <see cref="Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Strict"/> , and `null` convert to `true` and <see cref="Microsoft.Data.SqlClient.SqlConnectionEncryptOption.Optional"/> converts `false`. | ||
</para> | ||
</remarks> | ||
</SqlConnectionEncryptOption> | ||
<CanConvertFrom> | ||
<summary> | ||
If the source type is a string then conversion is allowed <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/>. | ||
</summary> | ||
<param name="value">A string containing the value to convert.</param> | ||
<returns> | ||
<see langword="true" /> if the <paramref name="value"/> parameter can be converted successfully; otherwise, <see langword="false" />. | ||
</returns> | ||
<remarks>This method does not throw an exception.</remarks> | ||
</CanConvertFrom> | ||
<ConvertFrom> | ||
<summary> | ||
Converts the specified string representation of a logical value to its <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/> equivalent. | ||
</summary> | ||
<param name="value">A string containing the value to convert.</param> | ||
<param name="result"> | ||
An object that is equivalent to <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/>. | ||
</param> | ||
<returns> | ||
An object that is equivalent to <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/> with value of <paramref name="value"/> if conversion was successful; | ||
otherwise, an exception is thrown. | ||
</returns> | ||
<remarks>This method throws an exception if conversion fails.</remarks> | ||
</ConvertFrom> | ||
<ConvertTo> | ||
<summary> | ||
Converts an object <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/> value to its string representation. | ||
</summary> | ||
<param name="value">An object <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/> containing the value to convert.</param> | ||
<param name="result"> | ||
A string representation of the value of <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/>. | ||
</param> | ||
<returns> | ||
A string representation of the value of <see cref="T:Microsoft.Data.SqlClient.SqlConnectionEncryptOption"/>. | ||
</returns> | ||
<remarks>This method does not throw an exception if conversion fails.</remarks> | ||
</ConvertTo> | ||
</members> | ||
</docs> |
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
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
46 changes: 46 additions & 0 deletions
46
...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,46 @@ | ||
// 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 System.Drawing; | ||
|
||
namespace Microsoft.Data.SqlClient | ||
{ | ||
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionEncryptOptionConverter.xml' path='docs/members[@name="SqlConnectionEncryptOptionConverter"]/SqlConnectionEncryptOptionConverter/*'/> | ||
public 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. | ||
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionEncryptOptionConverter.xml' path='docs/members[@name="SqlConnectionEncryptOptionConverter"]/SqlConnectionEncryptOptionConverter/CanConvertFrom/*'/> | ||
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) | ||
{ | ||
if (sourceType == typeof(string)) | ||
{ | ||
return true; | ||
} | ||
return base.CanConvertFrom(context, sourceType); | ||
} | ||
// Overrides the ConvertFrom method of TypeConverter. | ||
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionEncryptOptionConverter.xml' path='docs/members[@name="SqlConnectionEncryptOptionConverter"]/SqlConnectionEncryptOptionConverter/ConvertFrom/*'/> | ||
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) | ||
{ | ||
if (value is string) | ||
{ | ||
return SqlConnectionEncryptOption.Parse(value.ToString()); | ||
} | ||
throw new Exception("Value to convert must be of string type!"); | ||
} | ||
// Overrides the ConvertTo method of TypeConverter. | ||
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionEncryptOptionConverter.xml' path='docs/members[@name="SqlConnectionEncryptOptionConverter"]/SqlConnectionEncryptOptionConverter/ConvertTo/*'/> | ||
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) | ||
{ | ||
return base.ConvertTo(context, culture, value, destinationType); | ||
} | ||
} | ||
} |
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