44
55namespace Upsilon . Apps . Passkey . GUI . WPF . ViewModels
66{
7- internal class InsertIdentifierViewModel : INotifyPropertyChanged
7+ internal class InsertIdentifierViewModel ( IEnumerable < string > identifiers , string identifier ) : INotifyPropertyChanged
88 {
9- private readonly string [ ] _identifiers ;
9+ private readonly string [ ] _identifiers = [ .. identifiers ] ;
1010
11- public ObservableCollection < string > Identifiers ;
11+ public ObservableCollection < string > Identifiers = [ .. identifiers . Where ( x => x . StartsWith ( identifier . Trim ( ) , StringComparison . CurrentCultureIgnoreCase ) ) ,
12+ .. identifiers . Where ( x => x . Contains ( identifier . Trim ( ) , StringComparison . CurrentCultureIgnoreCase )
13+ && ! x . StartsWith ( identifier . Trim ( ) , StringComparison . CurrentCultureIgnoreCase ) ) ] ;
1214
1315 public string Identifier
1416 {
15- get ;
17+ get => field . Trim ( ) ;
1618 set
1719 {
18- _ = PropertyHelper . SetProperty ( ref field , value , this , PropertyChanged ) ;
20+ PropertyHelper . SetProperty ( ref field , value . Trim ( ) , this , PropertyChanged ) ;
1921 _refreshFilter ( ) ;
2022 }
21- } = string . Empty ;
23+ } = identifier ;
2224
2325 public event PropertyChangedEventHandler ? PropertyChanged ;
2426
@@ -27,24 +29,17 @@ protected virtual void OnPropertyChanged(string propertyName)
2729 PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( propertyName ) ) ;
2830 }
2931
30- public InsertIdentifierViewModel ( IEnumerable < string > identifiers )
31- {
32- _identifiers = [ .. identifiers . OrderBy ( x => x ) . Distinct ( ) ] ;
33- Identifiers = [ .. _identifiers ] ;
34- }
35-
3632 private void _refreshFilter ( )
3733 {
3834 Identifiers . Clear ( ) ;
3935
40- string identifier = Identifier . ToLower ( ) . Trim ( ) ;
41- string [ ] identifiers = [ .. _identifiers . Where ( x => x . StartsWith ( identifier , StringComparison . CurrentCultureIgnoreCase ) ) ,
42- .. _identifiers . Where ( x => x . Contains ( identifier , StringComparison . CurrentCultureIgnoreCase )
43- && ! x . StartsWith ( identifier , StringComparison . CurrentCultureIgnoreCase ) ) ] ;
36+ string [ ] identifiers = [ .. _identifiers . Where ( x => x . StartsWith ( Identifier , StringComparison . CurrentCultureIgnoreCase ) ) ,
37+ .. _identifiers . Where ( x => x . Contains ( Identifier , StringComparison . CurrentCultureIgnoreCase )
38+ && ! x . StartsWith ( Identifier , StringComparison . CurrentCultureIgnoreCase ) ) ] ;
4439
45- foreach ( string id in identifiers )
40+ foreach ( string identifier in identifiers )
4641 {
47- Identifiers . Add ( id ) ;
42+ Identifiers . Add ( identifier ) ;
4843 }
4944 }
5045 }
0 commit comments