From 4fd24a68df817a18105c06b8dc6f1724bacbaee7 Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 20 Apr 2018 22:26:47 +0100 Subject: [PATCH] Changes following PR comments --- .../SafeComWrappers/VB/VBControl.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBControl.cs b/Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBControl.cs index d1106b391a..4fac7188a1 100644 --- a/Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBControl.cs +++ b/Rubberduck.VBEditor.VB6/SafeComWrappers/VB/VBControl.cs @@ -22,22 +22,20 @@ public string Name { return string.Empty; } - - using (var properties = this.Properties) + try { - foreach (var property in properties) + using (var properties = this.Properties) + using (var property = properties["Name"]) { - using (property) - { - if (property.Name == "Name") - { - return (string)property.Value; - } - } + return property.Value as string; } } - // Should never happen - all VB controls are required to be named. - return null; + catch (Exception exception) + { + // Assumption - all VB controls are required to be named. + System.Diagnostics.Debug.Assert(false, "VBControl.get_Name failed.", $"{exception}"); + } + return string.Empty; } set { @@ -57,7 +55,8 @@ public string Name } } } - // Should never happen - all VB controls are required to be named. + // All VB controls are required to be named. + System.Diagnostics.Debug.Assert(false, "VBControl.set_Name failed: Name property not found."); } } }