refactor and fix compiler warning

This commit is contained in:
Sean Kaim
2017-03-17 17:02:15 -04:00
parent 30b37951b2
commit 3e664a7c2c
5 changed files with 22 additions and 11 deletions

View File

@@ -29,7 +29,7 @@ namespace mRemoteNGTests.UI.Controls
var textBox = new SecureTextBoxTester(_testForm.secureTextBox1.Name);
const string textToSend = "abc123";
textBox.Properties.Text = textToSend;
Assert.That(textBox.Properties.SecureString.ConvertToUnsecureString(), Is.EqualTo(textToSend));
Assert.That(textBox.Properties.SecString.ConvertToUnsecureString(), Is.EqualTo(textToSend));
}
}
}

View File

@@ -116,13 +116,14 @@ namespace mRemoteNG.UI.Controls
}
#endregion
// CodeAyalysis doesn't like null propagation
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "components")]
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
components?.Dispose();
if (!disposing) return;
components?.Dispose();
}
finally
{

View File

@@ -220,12 +220,14 @@ namespace mRemoteNG.UI.Controls
}
#endregion
// CodeAyalysis doesn't like null propagation
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "components")]
protected override void Dispose(bool disposing)
{
try
{
if (disposing)
components?.Dispose();
if (!disposing) return;
components?.Dispose();
}
finally
{

View File

@@ -11,13 +11,21 @@
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
// CodeAnalysis doesn't like null propagation, and possibly IDisposable auto properties (like SecString).
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "components")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "<SecString>k__BackingField")]
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
try
{
components.Dispose();
if (!disposing) return;
components?.Dispose();
SecString?.Dispose();
}
finally
{
base.Dispose(disposing);
}
base.Dispose(disposing);
}
#region Component Designer generated code

View File

@@ -7,7 +7,7 @@ namespace mRemoteNG.UI.Controls
{
public partial class SecureTextBox : TextBox
{
public SecureString SecureString { get; private set; } = new SecureString();
public SecureString SecString { get; private set; } = new SecureString();
public SecureTextBox()
{
@@ -17,7 +17,7 @@ namespace mRemoteNG.UI.Controls
private void SecureTextBox_TextChanged(object sender, System.EventArgs e)
{
SecureString = Text.ConvertToSecureString();
SecString = Text.ConvertToSecureString();
}
}
}