From 149a69784a781790e9212c9858afbbcd2577d316 Mon Sep 17 00:00:00 2001 From: oven425 Date: Fri, 5 Feb 2021 17:43:37 +0800 Subject: [PATCH] =?UTF-8?q?update=201.=20=E4=BF=AE=E6=94=B9join=E7=9A=84?= =?UTF-8?q?=E6=99=82=E5=80=99,=E6=B2=92=E6=9C=89=E5=B0=8D=E5=88=B0?= =?UTF-8?q?=E7=9A=84registrykey=E8=A6=81Dispose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QSoft.Reg/RegistryKeyEx.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/QSoft.Reg/RegistryKeyEx.cs b/QSoft.Reg/RegistryKeyEx.cs index 7961628..7a77c9c 100644 --- a/QSoft.Reg/RegistryKeyEx.cs +++ b/QSoft.Reg/RegistryKeyEx.cs @@ -87,44 +87,44 @@ public static IEnumerable Join(this RegistryKey src, I foreach (var subkeyname in subkeynames) { RegistryKey reg = src.OpenSubKey(subkeyname); + bool hastrue = false; foreach (var oo in inner) { if (check.Invoke(reg, oo) == true) { + hastrue = true; yield return resultSelector.Invoke(reg, oo); } } + if(hastrue == false) + { + reg.Dispose(); + } } } public static IEnumerable Join(this RegistryKey src, IEnumerable inner, Func outerKeySelector, Func innerKeySelector, Func resultSelector) { string[] subkeynames = src.GetSubKeyNames(); - //Dictionary> dic = new Dictionary>(); foreach (var subkeyname in subkeynames) { RegistryKey reg = src.OpenSubKey(subkeyname); TKey key_reg = outerKeySelector.Invoke(reg); + bool hastrue = false; foreach (var oo in inner) { TKey key = innerKeySelector.Invoke(oo); if (key.Equals(key_reg) == true) { - //if(dic.ContainsKey(reg) == true) - //{ - // dic[reg].Add(oo); - //} - //else - //{ - // dic.Add(reg, new List() { oo}); - //} - - + hastrue = true; yield return resultSelector.Invoke(reg, oo); - //yield break; } } + if (hastrue == false) + { + reg.Dispose(); + } } }