@@ -14,6 +14,8 @@ internal sealed class TableViewGenerator : ViewGenerator
1414 // tableBody to use for this instance of the ViewGenerator;
1515 private TableControlBody _tableBody ;
1616
17+ private List < MshResolvedExpressionParameterAssociation > _activeAssociationList ;
18+
1719 internal override void Initialize ( TerminatingErrorContext terminatingErrorContext , PSPropertyExpressionFactory mshExpressionFactory , TypeInfoDataBase db , ViewDefinition view , FormattingCommandLineParameters formatParameters )
1820 {
1921 base . Initialize ( terminatingErrorContext , mshExpressionFactory , db , view , formatParameters ) ;
@@ -34,51 +36,48 @@ internal override void Initialize(TerminatingErrorContext errorContext, PSProper
3436 _tableBody = ( TableControlBody ) this . dataBaseInfo . view . mainControl ;
3537 }
3638
37- List < MshParameter > rawMshParameterList = null ;
38-
39- if ( parameters != null )
40- rawMshParameterList = parameters . mshParameterList ;
39+ // Build the active association list (with ExcludeProperty filter applied)
40+ _activeAssociationList = BuildActiveAssociationList ( so ) ;
41+ }
4142
43+ /// <summary>
44+ /// Builds the raw association list for table formatting.
45+ /// </summary>
46+ protected override List < MshResolvedExpressionParameterAssociation > BuildRawAssociationList ( PSObject so , List < MshParameter > propertyList )
47+ {
4248 // check if we received properties from the command line
43- if ( rawMshParameterList is not null && rawMshParameterList . Count > 0 )
49+ if ( propertyList is not null && propertyList . Count > 0 )
4450 {
45- this . activeAssociationList = AssociationManager . ExpandTableParameters ( rawMshParameterList , so ) ;
51+ return AssociationManager . ExpandTableParameters ( propertyList , so ) ;
4652 }
47- else
53+
54+ // we did not get any properties:
55+ // try to get properties from the default property set of the object
56+ var list = AssociationManager . ExpandDefaultPropertySet ( so , this . expressionFactory ) ;
57+ if ( list . Count > 0 )
4858 {
49- // we did not get any properties:
50- // try to get properties from the default property set of the object
51- this . activeAssociationList = AssociationManager . ExpandDefaultPropertySet ( so , this . expressionFactory ) ;
52- if ( this . activeAssociationList . Count > 0 )
53- {
54- // we got a valid set of properties from the default property set..add computername for
55- // remoteobjects (if available)
56- if ( PSObjectHelper . ShouldShowComputerNameProperty ( so ) )
57- {
58- activeAssociationList . Add ( new MshResolvedExpressionParameterAssociation ( null ,
59- new PSPropertyExpression ( RemotingConstants . ComputerNameNoteProperty ) ) ) ;
60- }
61- }
62- else
59+ // we got a valid set of properties from the default property set..add computername for
60+ // remoteobjects (if available)
61+ if ( PSObjectHelper . ShouldShowComputerNameProperty ( so ) )
6362 {
64- // we failed to get anything from the default property set
65- this . activeAssociationList = AssociationManager . ExpandAll ( so ) ;
66- if ( this . activeAssociationList . Count > 0 )
67- {
68- // Remove PSComputerName and PSShowComputerName from the display as needed.
69- AssociationManager . HandleComputerNameProperties ( so , activeAssociationList ) ;
70- FilterActiveAssociationList ( ) ;
71- }
72- else
73- {
74- // we were unable to retrieve any properties, so we leave an empty list
75- this . activeAssociationList = new List < MshResolvedExpressionParameterAssociation > ( ) ;
76- return ;
77- }
63+ list . Add ( new MshResolvedExpressionParameterAssociation ( null ,
64+ new PSPropertyExpression ( RemotingConstants . ComputerNameNoteProperty ) ) ) ;
7865 }
66+
67+ return list ;
7968 }
8069
81- ApplyExcludePropertyFilter ( ) ;
70+ // we failed to get anything from the default property set
71+ list = AssociationManager . ExpandAll ( so ) ;
72+ if ( list . Count > 0 )
73+ {
74+ // Remove PSComputerName and PSShowComputerName from the display as needed.
75+ AssociationManager . HandleComputerNameProperties ( so , list ) ;
76+ return LimitAssociationListSize ( list ) ;
77+ }
78+
79+ // we were unable to retrieve any properties, so we leave an empty list
80+ return new List < MshResolvedExpressionParameterAssociation > ( ) ;
8281 }
8382
8483 /// <summary>
@@ -129,30 +128,29 @@ internal override FormatStartData GenerateStartData(PSObject so)
129128 }
130129
131130 /// <summary>
132- /// Method to filter resolved expressions as per table view needs .
131+ /// Limits the association list size for table view.
133132 /// For v1.0, table view supports only 10 properties.
134- ///
135- /// This method filters and updates "activeAssociationList" instance property.
136133 /// </summary>
137- /// <returns>None.</returns>
138- /// <remarks>This method updates "activeAssociationList" instance property.</remarks>
139- private void FilterActiveAssociationList ( )
134+ /// <param name="list">The list to limit.</param>
135+ /// <returns>The limited list.</returns>
136+ private static List < MshResolvedExpressionParameterAssociation > LimitAssociationListSize (
137+ List < MshResolvedExpressionParameterAssociation > list )
140138 {
141- // we got a valid set of properties from the default property set
142- // make sure we do not have too many properties
143-
144139 // NOTE: this is an arbitrary number, chosen to be a sensitive default
145- const int nMax = 10 ;
140+ const int maxCount = 10 ;
141+
142+ if ( list . Count <= maxCount )
143+ {
144+ return list ;
145+ }
146146
147- if ( activeAssociationList . Count > nMax )
147+ var result = new List < MshResolvedExpressionParameterAssociation > ( maxCount ) ;
148+ for ( int k = 0 ; k < maxCount ; k ++ )
148149 {
149- List < MshResolvedExpressionParameterAssociation > tmp = this . activeAssociationList ;
150- this . activeAssociationList = new List < MshResolvedExpressionParameterAssociation > ( ) ;
151- for ( int k = 0 ; k < nMax ; k ++ )
152- this . activeAssociationList . Add ( tmp [ k ] ) ;
150+ result . Add ( list [ k ] ) ;
153151 }
154152
155- return ;
153+ return result ;
156154 }
157155
158156 private TableHeaderInfo GenerateTableHeaderInfoFromDataBaseInfo ( PSObject so )
@@ -228,9 +226,9 @@ private TableHeaderInfo GenerateTableHeaderInfoFromProperties(PSObject so)
228226 thi . hideHeader = this . HideHeaders ;
229227 thi . repeatHeader = this . RepeatHeader ;
230228
231- for ( int k = 0 ; k < this . activeAssociationList . Count ; k ++ )
229+ for ( int k = 0 ; k < _activeAssociationList . Count ; k ++ )
232230 {
233- MshResolvedExpressionParameterAssociation a = this . activeAssociationList [ k ] ;
231+ MshResolvedExpressionParameterAssociation a = _activeAssociationList [ k ] ;
234232 TableColumnInfo ci = new TableColumnInfo ( ) ;
235233
236234 // set the label of the column
@@ -241,7 +239,7 @@ private TableHeaderInfo GenerateTableHeaderInfoFromProperties(PSObject so)
241239 ci . propertyName = ( string ) key ;
242240 }
243241
244- ci . propertyName ??= this . activeAssociationList [ k ] . ResolvedExpression . ToString ( ) ;
242+ ci . propertyName ??= _activeAssociationList [ k ] . ResolvedExpression . ToString ( ) ;
245243
246244 // set the width of the table
247245 if ( a . OriginatingParameter != null )
@@ -473,13 +471,13 @@ private TableRowEntry GenerateTableRowEntryFromDataBaseInfo(PSObject so, int enu
473471 private TableRowEntry GenerateTableRowEntryFromFromProperties ( PSObject so , int enumerationLimit )
474472 {
475473 TableRowEntry tre = new TableRowEntry ( ) ;
476- for ( int k = 0 ; k < this . activeAssociationList . Count ; k ++ )
474+ for ( int k = 0 ; k < _activeAssociationList . Count ; k ++ )
477475 {
478476 FormatPropertyField fpf = new FormatPropertyField ( ) ;
479477 FieldFormattingDirective directive = null ;
480- if ( activeAssociationList [ k ] . OriginatingParameter != null )
478+ if ( _activeAssociationList [ k ] . OriginatingParameter != null )
481479 {
482- directive = activeAssociationList [ k ] . OriginatingParameter . GetEntry ( FormatParameterDefinitionKeys . FormatStringEntryKey ) as FieldFormattingDirective ;
480+ directive = _activeAssociationList [ k ] . OriginatingParameter . GetEntry ( FormatParameterDefinitionKeys . FormatStringEntryKey ) as FieldFormattingDirective ;
483481 }
484482
485483 if ( directive is null )
@@ -488,7 +486,7 @@ private TableRowEntry GenerateTableRowEntryFromFromProperties(PSObject so, int e
488486 directive . isTable = true ;
489487 }
490488
491- fpf . propertyValue = this . GetExpressionDisplayValue ( so , enumerationLimit , this . activeAssociationList [ k ] . ResolvedExpression , directive ) ;
489+ fpf . propertyValue = this . GetExpressionDisplayValue ( so , enumerationLimit , _activeAssociationList [ k ] . ResolvedExpression , directive ) ;
492490 tre . formatPropertyFieldList . Add ( fpf ) ;
493491 }
494492
0 commit comments