1+ using System ;
2+ using System . Collections ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
5+ using System . Management . Automation ;
6+ using System . Management . Automation . Language ;
7+ using System . Reflection . Metadata ;
8+ using Microsoft . SharePoint . Client ;
9+ using PnP . Framework . Utilities ;
10+
11+ namespace PnP . PowerShell . Commands . Base . Completers
12+ {
13+ public sealed class PropertyBagKeyCompleter : IArgumentCompleter
14+ {
15+ public IEnumerable < CompletionResult > CompleteArgument ( string commandName , string parameterName , string wordToComplete , CommandAst commandAst , IDictionary fakeBoundParameters )
16+ {
17+ wordToComplete = wordToComplete . Trim ( '"' ) ;
18+
19+ IEnumerable < string > keys = null ;
20+ if ( fakeBoundParameters [ "Folder" ] == null )
21+ {
22+ PnPConnection . Current . Context . Web . EnsureProperty ( w => w . AllProperties ) ;
23+
24+ keys = PnPConnection . Current . Context . Web . AllProperties . FieldValues . Select ( x => x . Key ) ;
25+ }
26+ else
27+ {
28+ var folderName = fakeBoundParameters [ "Folder" ] as string ;
29+ PnPConnection . Current . Context . Web . EnsureProperty ( w => w . ServerRelativeUrl ) ;
30+
31+ var folderUrl = UrlUtility . Combine ( PnPConnection . Current . Context . Web . ServerRelativeUrl , folderName ) ;
32+ var folder = PnPConnection . Current . Context . Web . GetFolderByServerRelativePath ( ResourcePath . FromDecodedUrl ( folderUrl ) ) ;
33+ folder . EnsureProperty ( f => f . Properties ) ;
34+
35+ keys = folder . Properties . FieldValues . Select ( x => x . Key ) ;
36+
37+ }
38+
39+ foreach ( var key in keys . Where ( k => k . StartsWith ( wordToComplete , StringComparison . InvariantCultureIgnoreCase ) ) )
40+ {
41+ yield return new CompletionResult ( $ "\" { key } \" ") ;
42+ }
43+ }
44+ }
45+ }
0 commit comments