forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeaderInfo.cs
More file actions
61 lines (50 loc) · 2.01 KB
/
Copy pathHeaderInfo.cs
File metadata and controls
61 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// Copyright (C) Microsoft. All rights reserved.
//
namespace Microsoft.PowerShell.Commands
{
using System;
using System.Collections.Generic;
using System.Management.Automation;
internal class HeaderInfo
{
private List<ColumnInfo> _columns = new List<ColumnInfo>();
internal void AddColumn(ColumnInfo col)
{
_columns.Add(col);
}
internal PSObject AddColumnsToWindow(OutWindowProxy windowProxy, PSObject liveObject)
{
PSObject staleObject = new PSObject();
// Initiate arrays to be of the same size.
int count = _columns.Count;
string[] propertyNames = new string[count];
string[] displayNames = new string[count];
Type[] types = new Type[count];
count = 0; // Reuse this variable to count cycles.
foreach (ColumnInfo column in _columns)
{
propertyNames[count] = column.StaleObjectPropertyName();
displayNames[count] = column.DisplayName();
Object columnValue = null;
types[count] = column.GetValueType(liveObject, out columnValue);
// Add a property to the stale object since a column value has been evaluated to get column's type.
staleObject.Properties.Add(new PSNoteProperty(propertyNames[count], columnValue));
count++;
}
windowProxy.AddColumns(propertyNames, displayNames, types);
return staleObject;
}
internal PSObject CreateStalePSObject(PSObject liveObject)
{
PSObject staleObject = new PSObject();
foreach (ColumnInfo column in _columns)
{
// Add a property to the stale PSObject.
staleObject.Properties.Add(new PSNoteProperty(column.StaleObjectPropertyName(),
column.GetValue(liveObject)));
}
return staleObject;
}
}
}