Exemple #1
0
        static AssemblySource()
        {
            Instance.CollectionChanged += (s, e) =>
            {
                switch (e.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    e.NewItems.OfType <Assembly>()
                    .SelectMany(a => ExtractTypes(a))
                    .Apply(t => TypeNameCache.Add(t.FullName, t));
                    break;

                case NotifyCollectionChangedAction.Remove:
                case NotifyCollectionChangedAction.Replace:
                case NotifyCollectionChangedAction.Reset:
                    TypeNameCache.Clear();
                    Instance
                    .SelectMany(a => ExtractTypes(a))
                    .Apply(AddToCache);
                    break;
                }
            };
        }
Exemple #2
0
 /// <summary>
 /// Finds a type which matches one of the elements in the sequence of names.
 /// </summary>
 public static Type FindTypeByNames(IEnumerable <string> names)
 {
     return(names?
            .Join(Assemblies.SelectMany(a => a.GetExportedTypes()), name => name, exportedType => exportedType.FullName, (name, exportedType) => exportedType)
            .FirstOrDefault());
 }