var searchTarget = typeof(ITarget<>);
var dict = Assembly.GetExecutingAssembly()
.GetTypes()
.SelectMany(t => t.GetInterfaces()
.Where(i => i.IsGenericType
&& (i.GetGenericTypeDefinition() == searchTarget)
&& !i.ContainsGenericParameters),
(t, i) => new { Key = i.GetGenericArguments()[0], Value = t })
.ToDictionary(x => x.Key, x => x.Value);
, , ITarget<> - , class Foo : ITarget<string> class Bar : ITarget<string> - ToDictionary ArgumentException, , .
" ", .
ToLookup ToDictionary Lookup<K,V>:
var dict = Assembly.GetExecutingAssembly()
.GetTypes()
.SelectMany()
.ToLookup(x => x.Key, x => x.Value);
- Dictionary<K,List<V>>, :
var dict = Assembly.GetExecutingAssembly()
.GetTypes()
.SelectMany()
.GroupBy(x => x.Key, x => x.Value)
.ToDictionary(g => g.Key, g => g.ToList());