1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Collections . ObjectModel ;
4+ using System . ComponentModel ;
5+ using System . Linq ;
6+ using System . Reflection ;
7+ using System . Runtime . CompilerServices ;
8+ using System . Runtime . Loader ;
9+ using System . Text ;
10+ using System . Threading . Tasks ;
11+ using System . Windows ;
12+ using System . Windows . Controls ;
13+ using System . Windows . Data ;
14+ using System . Windows . Documents ;
15+ using System . Windows . Input ;
16+ using System . Windows . Media ;
17+ using System . Windows . Media . Imaging ;
18+ using System . Windows . Shapes ;
19+ using RevitDBExplorer . WPF ;
20+
21+ // (c) Revit Database Explorer https://github.com/NeVeSpl/RevitDBExplorer/blob/main/license.md
22+
23+ namespace RevitDBExplorer
24+ {
25+
26+ public partial class Assemblies : Window , INotifyPropertyChanged
27+ {
28+ public ObservableCollection < AssemblyViewModel > Items { get ; set ; } = new ObservableCollection < AssemblyViewModel > ( ) ;
29+
30+
31+
32+ public Assemblies ( )
33+ {
34+ InitializeComponent ( ) ;
35+
36+ var viewModels = AppDomain . CurrentDomain . GetAssemblies ( ) . Select ( ( x , i ) => new AssemblyViewModel ( i , x ) ) ;
37+ Items = new ObservableCollection < AssemblyViewModel > ( viewModels ) ;
38+
39+ this . DataContext = this ;
40+ }
41+
42+
43+
44+
45+
46+ #region INotifyPropertyChanged
47+
48+ public event PropertyChangedEventHandler PropertyChanged ;
49+
50+ protected virtual void OnPropertyChanged ( [ CallerMemberName ] String propertyName = "" )
51+ {
52+ PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
53+ }
54+
55+ #endregion
56+
57+ private void TextBox_TextChanged ( object sender , TextChangedEventArgs e )
58+ {
59+ var lcv = ( ListCollectionView ) CollectionViewSource . GetDefaultView ( Items ) ;
60+ lcv . Filter = Filter ;
61+ }
62+
63+ private bool Filter ( object item )
64+ {
65+ if ( item is AssemblyViewModel assemblyViewModel )
66+ {
67+ return assemblyViewModel . Filter ( cFilter . Text ) ;
68+ }
69+ return true ;
70+ }
71+ }
72+
73+
74+
75+ public class AssemblyViewModel : BaseViewModel
76+ {
77+ public int No { get ; set ; }
78+ public string Name { get ; set ; }
79+ public string Version { get ; private set ; }
80+ public string Path { get ; private set ; }
81+ public string AssemblyLoadContext { get ; private set ; }
82+
83+
84+ public AssemblyViewModel ( int no , Assembly asm )
85+ {
86+ No = no + 1 ;
87+
88+ var asmName = asm . GetName ( ) ;
89+ Name = asmName . Name ;
90+ Version = asmName . Version ? . ToString ( ) ;
91+ Path = asm . IsDynamic ? string . Empty : asm . Location ;
92+ #if R2025_MIN
93+ var context = System . Runtime . Loader . AssemblyLoadContext . GetLoadContext ( asm ) ;
94+ AssemblyLoadContext = context . Name ;
95+ #endif
96+
97+ }
98+
99+
100+ public bool Filter ( string text )
101+ {
102+ if ( string . IsNullOrEmpty ( text ) ) return true ;
103+ if ( Name ? . Contains ( text , StringComparison . OrdinalIgnoreCase ) == true ) return true ;
104+ if ( Path ? . Contains ( text , StringComparison . OrdinalIgnoreCase ) == true ) return true ;
105+ if ( AssemblyLoadContext ? . Contains ( text , StringComparison . OrdinalIgnoreCase ) == true ) return true ;
106+ if ( Version ? . Contains ( text , StringComparison . OrdinalIgnoreCase ) == true ) return true ;
107+
108+ return false ;
109+ }
110+ }
111+ }
0 commit comments