From 6420d47abc99ce78fa13aa0bc232f9b95979e932 Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 5 Apr 2018 14:49:56 -0600 Subject: [PATCH] Fixed problem with GetAllTypes extension method --- Core/BkwdComp/Linq.NET2.cs | 20 ++++++++++++++++++++ Core/Extensions/ReflectionExtensions.cs | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Core/BkwdComp/Linq.NET2.cs b/Core/BkwdComp/Linq.NET2.cs index 9c6ec867..24210c2f 100644 --- a/Core/BkwdComp/Linq.NET2.cs +++ b/Core/BkwdComp/Linq.NET2.cs @@ -314,11 +314,31 @@ namespace System.Linq /// An whose elements are the result of invoking the transform function on each element of . public static IEnumerable Select(this IEnumerable source, Func selector) { + if (source == null) throw new ArgumentNullException(nameof(source)); if (selector == null) throw new ArgumentNullException(nameof(selector)); foreach (var i in source) yield return selector(i); } + /// Projects each element of a sequence to an and flattens the resulting sequences into one sequence. + /// The type of the elements of . + /// The type of the elements of the sequence returned by . + /// A sequence of values to project. + /// A transform function to apply to each element. + /// An whose elements are the result of invoking the one-to-many transform function on each element of the input sequence. + public static IEnumerable SelectMany(this IEnumerable source, Func> selector) + { + if (source == null) throw new ArgumentNullException(nameof(source)); + if (selector == null) throw new ArgumentNullException(nameof(selector)); + foreach (TSource element in source) + { + foreach (TResult subElement in selector(element)) + { + yield return subElement; + } + } + } + /// Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. /// The type of the elements of . /// An to return a single element from. diff --git a/Core/Extensions/ReflectionExtensions.cs b/Core/Extensions/ReflectionExtensions.cs index 61a4fd35..f29f2c72 100644 --- a/Core/Extensions/ReflectionExtensions.cs +++ b/Core/Extensions/ReflectionExtensions.cs @@ -12,7 +12,7 @@ namespace Vanara.Extensions /// Gets all loaded types in the . /// The application domain. /// All loaded types. - public static IEnumerable GetAllTypes(this AppDomain appDomain) => appDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()); + public static IEnumerable GetAllTypes(this AppDomain appDomain) => appDomain.GetAssemblies().SelectMany(a => a.GetTypes()); /// Returns an array of custom attributes applied to this member and identified by . /// The type of attribute to search for. Only attributes that are assignable to this type are returned. @@ -178,8 +178,8 @@ namespace Vanara.Extensions try { asm = Assembly.LoadFrom(asmRef); } catch { } if (!TryGetType(asm, typeName, ref ret)) { - foreach (asm in AppDomain.CurrentDomain.GetAssemblies()) - if (TryGetType(asm, typeName, ref ret)) break; + foreach (var asm2 in AppDomain.CurrentDomain.GetAssemblies()) + if (TryGetType(asm2, typeName, ref ret)) break; } return ret; }