There is exactly one type in the code that implements IResourceConverter. This is what the following two linq expressions are looking for. The first does not find. The latter does. However, both are equivalent syntaxes (or at least should be!).
Linq Statement 1:
List<Type> toInstantiate = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.Where(type => typeof(IResourceConverter).IsAssignableFrom(type)
&& type != typeof(IResourceConverter))
.ToList();
This returns 0 results.
Linq Statement 2:
I left linq intact, with the exception of the where clause, which I broke out, and made an equivalent with the foreach loop
List<Type> toInstantiate = new List<Type>();
List<Type> allTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(assembly => assembly.GetTypes())
.ToList();
foreach (Type t in allTypes)
{
if (typeof(IResourceConverter).IsAssignableFrom(t)
&& t != typeof(IResourceConverter))
toInstantiate.Add(t);
}
In this case, toInstantiate has 1 result ... exactly what I expected.
Any explanation for this weird behavior?
source
share