From 52a79ef9eccafc3efc4fc4219aa441bb91a1b2d5 Mon Sep 17 00:00:00 2001 From: A-tG Date: Sun, 1 May 2022 15:31:20 +0300 Subject: [PATCH] moved repeated code into method --- VoicemeeterOsdProgram/Options/OsdOptions.cs | 32 +++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/VoicemeeterOsdProgram/Options/OsdOptions.cs b/VoicemeeterOsdProgram/Options/OsdOptions.cs index 17a5f68..2e2de30 100644 --- a/VoicemeeterOsdProgram/Options/OsdOptions.cs +++ b/VoicemeeterOsdProgram/Options/OsdOptions.cs @@ -81,15 +81,7 @@ public HashSet AlwaysShowElements get => m_alwaysShowElements; set { - if ((value.Count > 1) && value.Contains(StripElements.None)) - { - value.Remove(StripElements.None); - } - if (value.Count == 0) - { - value.Add(StripElements.None); - } - + HandleStripElementsCollection(value); HandlePropertyChange(ref m_alwaysShowElements, ref value, AlwaysShowElementsChanged); } } @@ -100,15 +92,7 @@ public HashSet NeverShowElements get => m_neverShowElements; set { - if ((value.Count > 1) && value.Contains(StripElements.None)) - { - value.Remove(StripElements.None); - } - if (value.Count == 0) - { - value.Add(StripElements.None); - } - + HandleStripElementsCollection(value); HandlePropertyChange(ref m_neverShowElements, ref value, NeverShowElementsChanged); } } @@ -160,6 +144,18 @@ public override bool TryParseTo(string fromPropertyName, out string toVal) } } + private void HandleStripElementsCollection(ICollection elements) + { + if ((elements.Count > 1) && elements.Contains(StripElements.None)) + { + elements.Remove(StripElements.None); + } + if (elements.Count == 0) + { + elements.Add(StripElements.None); + } + } + public event EventHandler DontShowIfVoicemeeterVisibleChanged; public event EventHandler IsInteractableChanged; public event EventHandler DurationMsChanged;