File size: 29,864 Bytes
8c763fb | 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 | // Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// this file contains the data structures for the in memory database
// containing display and formatting information
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.PowerShell.Commands;
using Microsoft.PowerShell.Commands.Internal.Format;
namespace Microsoft.PowerShell.Commands.Internal.Format
{
internal enum EnumerableExpansion
{
/// <summary>
/// Process core only, ignore IEumerable.
/// </summary>
CoreOnly,
/// <summary>
/// Process IEnumerable, ignore core.
/// </summary>
EnumOnly,
/// <summary>
/// Process both core and IEnumerable, core first.
/// </summary>
Both,
}
#region Type Info Database
internal sealed partial class TypeInfoDataBase
{
// define the sections corresponding the XML file
internal DefaultSettingsSection defaultSettingsSection = new DefaultSettingsSection();
internal TypeGroupsSection typeGroupSection = new TypeGroupsSection();
internal ViewDefinitionsSection viewDefinitionsSection = new ViewDefinitionsSection();
internal FormatControlDefinitionHolder formatControlDefinitionHolder = new FormatControlDefinitionHolder();
/// <summary>
/// Cache for resource strings in format.ps1xml.
/// </summary>
internal DisplayResourceManagerCache displayResourceManagerCache = new DisplayResourceManagerCache();
}
internal sealed class DatabaseLoadingInfo
{
internal string fileDirectory = null;
internal string filePath = null;
internal bool isFullyTrusted = false;
internal bool isProductCode = false;
internal string xPath = null;
internal DateTime loadTime = DateTime.Now;
}
#endregion
#region Default Settings
#if _LATER
internal class SettableOnceValue<T>
{
SettableOnceValue (T defaultValue)
{
this._default = defaultValue;
}
internal void f(T x)
{
Nullable<T> y = x;
this._value = y;
// this._value = (Nullable<T>)x;
}
internal T Value
{
/*
set
{
if (_value == null)
{
this._value = value;
}
}
*/
get
{
if (_value != null)
return this._value.Value;
return _default;
}
}
private Nullable<T> _value;
private T _default;
}
#endif
internal sealed class DefaultSettingsSection
{
internal bool MultilineTables
{
get
{
if (_multilineTables.HasValue)
return _multilineTables.Value;
return false;
}
set
{
if (!_multilineTables.HasValue)
{
_multilineTables = value;
}
}
}
private bool? _multilineTables;
internal FormatErrorPolicy formatErrorPolicy = new FormatErrorPolicy();
internal ShapeSelectionDirectives shapeSelectionDirectives = new ShapeSelectionDirectives();
internal List<EnumerableExpansionDirective> enumerableExpansionDirectiveList = new List<EnumerableExpansionDirective>();
}
internal sealed class FormatErrorPolicy
{
/// <summary>
/// If true, display error messages.
/// </summary>
internal bool ShowErrorsAsMessages
{
get
{
if (_showErrorsAsMessages.HasValue)
return _showErrorsAsMessages.Value;
return false;
}
set
{
if (!_showErrorsAsMessages.HasValue)
{
_showErrorsAsMessages = value;
}
}
}
private bool? _showErrorsAsMessages;
/// <summary>
/// If true, display an error string in the formatted display
/// (e.g. cell in a table)
/// </summary>
internal bool ShowErrorsInFormattedOutput
{
get
{
if (_showErrorsInFormattedOutput.HasValue)
return _showErrorsInFormattedOutput.Value;
return false;
}
set
{
if (!_showErrorsInFormattedOutput.HasValue)
{
_showErrorsInFormattedOutput = value;
}
}
}
private bool? _showErrorsInFormattedOutput;
/// <summary>
/// String to display in the formatted display (e.g. cell in a table)
/// when the evaluation of a PSPropertyExpression fails.
/// </summary>
internal string errorStringInFormattedOutput = "#ERR";
/// <summary>
/// String to display in the formatted display (e.g. cell in a table)
/// when a format operation on a value fails.
/// </summary>
internal string formatErrorStringInFormattedOutput = "#FMTERR";
}
internal sealed class ShapeSelectionDirectives
{
internal int PropertyCountForTable
{
get
{
if (_propertyCountForTable.HasValue)
return _propertyCountForTable.Value;
return 4;
}
set
{
if (!_propertyCountForTable.HasValue)
{
_propertyCountForTable = value;
}
}
}
private int? _propertyCountForTable;
internal List<FormatShapeSelectionOnType> formatShapeSelectionOnTypeList = new List<FormatShapeSelectionOnType>();
}
internal enum FormatShape { Table, List, Wide, Complex, Undefined }
internal abstract class FormatShapeSelectionBase
{
internal FormatShape formatShape = FormatShape.Undefined;
}
internal sealed class FormatShapeSelectionOnType : FormatShapeSelectionBase
{
internal AppliesTo appliesTo;
}
internal sealed class EnumerableExpansionDirective
{
internal EnumerableExpansion enumerableExpansion = EnumerableExpansion.EnumOnly;
internal AppliesTo appliesTo;
}
#endregion
#region Type Groups Definitions
internal sealed class TypeGroupsSection
{
internal List<TypeGroupDefinition> typeGroupDefinitionList = new List<TypeGroupDefinition>();
}
internal sealed class TypeGroupDefinition
{
internal string name;
internal List<TypeReference> typeReferenceList = new List<TypeReference>();
}
internal abstract class TypeOrGroupReference
{
internal string name;
/// <summary>
/// Optional expression for conditional binding.
/// </summary>
internal ExpressionToken conditionToken = null;
}
internal sealed class TypeReference : TypeOrGroupReference
{
}
internal sealed class TypeGroupReference : TypeOrGroupReference
{
}
#endregion
#region Elementary Tokens
internal abstract class FormatToken
{
}
internal sealed class TextToken : FormatToken
{
internal string text;
internal StringResourceReference resource;
}
internal sealed class NewLineToken : FormatToken
{
internal int count = 1;
}
internal sealed class FrameToken : FormatToken
{
/// <summary>
/// Item associated with this frame definition.
/// </summary>
internal ComplexControlItemDefinition itemDefinition = new ComplexControlItemDefinition();
/// <summary>
/// Frame info associated with this frame definition.
/// </summary>
internal FrameInfoDefinition frameInfoDefinition = new FrameInfoDefinition();
}
internal sealed class FrameInfoDefinition
{
/// <summary>
/// Left indentation for a frame is relative to the parent frame.
/// it must be a value >=0.
/// </summary>
internal int leftIndentation = 0;
/// <summary>
/// Right indentation for a frame is relative to the parent frame.
/// it must be a value >=0.
/// </summary>
internal int rightIndentation = 0;
/// <summary>
/// It can have the following values:
/// 0 : ignore
/// greater than 0 : it represents the indentation for the first line (i.e. "first line indent").
/// The first line will be indented by the indicated number of characters.
/// less than 0 : it represents the hanging of the first line WRT the following ones
/// (i.e. "first line hanging").
/// </summary>
internal int firstLine = 0;
}
internal sealed class ExpressionToken
{
internal ExpressionToken() { }
internal ExpressionToken(string expressionValue, bool isScriptBlock)
{
this.expressionValue = expressionValue;
this.isScriptBlock = isScriptBlock;
}
internal bool isScriptBlock;
internal string expressionValue;
}
internal abstract class PropertyTokenBase : FormatToken
{
/// <summary>
/// Optional expression for conditional binding.
/// </summary>
internal ExpressionToken conditionToken = null;
internal ExpressionToken expression = new ExpressionToken();
internal bool enumerateCollection = false;
}
internal sealed class CompoundPropertyToken : PropertyTokenBase
{
/// <summary>
/// An inline control or a reference to a control definition.
/// </summary>
internal ControlBase control = null;
}
internal sealed class FieldPropertyToken : PropertyTokenBase
{
internal FieldFormattingDirective fieldFormattingDirective = new FieldFormattingDirective();
}
internal sealed class FieldFormattingDirective
{
internal string formatString = null; // optional
internal bool isTable = false;
}
#endregion Elementary Tokens
#region Control Definitions: common data
/// <summary>
/// Root class for all the control types.
/// </summary>
internal abstract class ControlBase
{
internal static string GetControlShapeName(ControlBase control)
{
if (control is TableControlBody)
{
return nameof(FormatShape.Table);
}
if (control is ListControlBody)
{
return nameof(FormatShape.List);
}
if (control is WideControlBody)
{
return nameof(FormatShape.Wide);
}
if (control is ComplexControlBody)
{
return nameof(FormatShape.Complex);
}
return string.Empty;
}
/// <summary>
/// Returns a Shallow Copy of the current object.
/// </summary>
/// <returns></returns>
internal virtual ControlBase Copy()
{
System.Management.Automation.Diagnostics.Assert(false,
"This should never be called directly on the base. Let the derived class implement this method.");
return this;
}
}
/// <summary>
/// Reference to a control.
/// </summary>
internal sealed class ControlReference : ControlBase
{
/// <summary>
/// Name of the control we refer to, it cannot be null.
/// </summary>
internal string name = null;
/// <summary>
/// Type of the control we refer to, it cannot be null.
/// </summary>
internal Type controlType = null;
}
/// <summary>
/// Base class for all control definitions
/// NOTE: this is an extensibility point, if a new control
/// needs to be created, it has to be derived from this class.
/// </summary>
internal abstract class ControlBody : ControlBase
{
/// <summary>
/// RULE: valid only for table and wide only.
/// </summary>
internal bool? autosize = null;
/// <summary>
/// RULE: only valid for table.
/// </summary>
internal bool repeatHeader = false;
}
/// <summary>
/// Class to hold a definition of a control.
/// </summary>
internal sealed class ControlDefinition
{
/// <summary>
/// Name of the control we define, it cannot be null.
/// </summary>
internal string name = null;
/// <summary>
/// Body of the control we define, it cannot be null.
/// </summary>
internal ControlBody controlBody = null;
}
#endregion
#region View Definitions: common data
internal sealed class ViewDefinitionsSection
{
internal List<ViewDefinition> viewDefinitionList = new List<ViewDefinition>();
}
internal sealed partial class AppliesTo
{
// it can contain either a type or type group reference
internal List<TypeOrGroupReference> referenceList = new List<TypeOrGroupReference>();
}
internal sealed class GroupBy
{
internal StartGroup startGroup = new StartGroup();
// NOTE: extension point for describing:
// * end group statistics
// * end group footer
// This can be done with defining a new Type called EndGroup with fields
// such as stat and footer.
}
internal sealed class StartGroup
{
/// <summary>
/// Expression to be used to select the grouping.
/// </summary>
internal ExpressionToken expression = null;
/// <summary>
/// An inline control or a reference to a control definition.
/// </summary>
internal ControlBase control = null;
/// <summary>
/// Alternative (and simplified) representation for the control
/// RULE: if the control object is null, use this one.
/// </summary>
internal TextToken labelTextToken = null;
}
/// <summary>
/// Container for control definitions.
/// </summary>
internal sealed class FormatControlDefinitionHolder
{
/// <summary>
/// List of control definitions.
/// </summary>
internal List<ControlDefinition> controlDefinitionList = new List<ControlDefinition>();
}
/// <summary>
/// Definition of a view.
/// </summary>
internal sealed class ViewDefinition
{
internal DatabaseLoadingInfo loadingInfo;
/// <summary>
/// The name of this view. Must not be null.
/// </summary>
internal string name;
/// <summary>
/// Applicability of the view. Mandatory.
/// </summary>
internal AppliesTo appliesTo = new AppliesTo();
/// <summary>
/// Optional grouping directive.
/// </summary>
internal GroupBy groupBy;
/// <summary>
/// Container for optional local formatting directives.
/// </summary>
internal FormatControlDefinitionHolder formatControlDefinitionHolder = new FormatControlDefinitionHolder();
/// <summary>
/// Main control for the view (e.g. reference to a control or a control body.
/// </summary>
internal ControlBase mainControl;
/// <summary>
/// RULE: only valid for list and complex.
/// </summary>
internal bool outOfBand;
/// <summary>
/// Set if the view is for help output, used so we can prune the view from Get-FormatData
/// because those views are too complicated and big for remoting.
/// </summary>
internal bool isHelpFormatter;
internal Guid InstanceId { get; private set; }
internal ViewDefinition()
{
InstanceId = Guid.NewGuid();
}
}
/// <summary>
/// Base class for all the "shape"-Directive classes.
/// </summary>
internal abstract class FormatDirective
{
}
#endregion
#region Localized Resources
internal sealed class StringResourceReference
{
internal DatabaseLoadingInfo loadingInfo = null;
internal string assemblyName = null;
internal string assemblyLocation = null;
internal string baseName = null;
internal string resourceId = null;
}
#endregion
}
namespace System.Management.Automation
{
/// <summary>
/// Specifies additional type definitions for an object.
/// </summary>
public sealed class ExtendedTypeDefinition
{
/// <summary>
/// A format definition may apply to multiple types. This api returns
/// the first typename that this format definition applies to, but there
/// may be other types that apply. <see cref="TypeNames"/> should be
/// used instead.
/// </summary>
public string TypeName
{
get { return TypeNames[0]; }
}
/// <summary>
/// The list of type names this set of format definitions applies to.
/// </summary>
public List<string> TypeNames { get; internal set; }
/// <summary>
/// The formatting view definition for
/// the specified type.
/// </summary>
public List<FormatViewDefinition> FormatViewDefinition { get; internal set; }
/// <summary>
/// Overloaded to string method for
/// better display.
/// </summary>
/// <returns></returns>
public override string ToString()
{
return TypeName;
}
/// <summary>
/// Constructor for the ExtendedTypeDefinition.
/// </summary>
/// <param name="typeName"></param>
/// <param name="viewDefinitions"></param>
public ExtendedTypeDefinition(string typeName, IEnumerable<FormatViewDefinition> viewDefinitions) : this()
{
if (string.IsNullOrEmpty(typeName))
throw PSTraceSource.NewArgumentNullException(nameof(typeName));
if (viewDefinitions == null)
throw PSTraceSource.NewArgumentNullException(nameof(viewDefinitions));
TypeNames.Add(typeName);
foreach (FormatViewDefinition definition in viewDefinitions)
{
FormatViewDefinition.Add(definition);
}
}
/// <summary>
/// Initiate an instance of ExtendedTypeDefinition with the type name.
/// </summary>
/// <param name="typeName"></param>
public ExtendedTypeDefinition(string typeName) : this()
{
if (string.IsNullOrEmpty(typeName))
throw PSTraceSource.NewArgumentNullException(nameof(typeName));
TypeNames.Add(typeName);
}
internal ExtendedTypeDefinition()
{
FormatViewDefinition = new List<FormatViewDefinition>();
TypeNames = new List<string>();
}
}
/// <summary>
/// Defines a formatting view for a particular type.
/// </summary>
[DebuggerDisplay("{Name}")]
public sealed class FormatViewDefinition
{
/// <summary>Name of the formatting view as defined in the formatting file</summary>
public string Name { get; }
/// <summary>The control defined by this formatting view can be one of table, list, wide, or custom</summary>
public PSControl Control { get; }
/// <summary>instance id of the original view this will be used to distinguish two views with the same name and control types</summary>
internal Guid InstanceId { get; set; }
internal FormatViewDefinition(string name, PSControl control, Guid instanceid)
{
Name = name;
Control = control;
InstanceId = instanceid;
}
/// <summary/>
public FormatViewDefinition(string name, PSControl control)
{
if (string.IsNullOrEmpty(name))
throw PSTraceSource.NewArgumentNullException(nameof(name));
if (control == null)
throw PSTraceSource.NewArgumentNullException(nameof(control));
Name = name;
Control = control;
InstanceId = Guid.NewGuid();
}
}
/// <summary>
/// Defines a control for the formatting types defined by PowerShell.
/// </summary>
public abstract class PSControl
{
/// <summary>
/// Each control can group items and specify a header for the group.
/// You can group by same property value, or result of evaluating a script block.
/// </summary>
public PSControlGroupBy GroupBy { get; set; }
/// <summary>
/// When the "shape" of formatting has been determined by previous objects,
/// sometimes you want objects of different types to continue using that shape
/// (table, list, or whatever) even if they specify their own views, and sometimes
/// you want your view to take over. When OutOfBand is true, the view will apply
/// regardless of previous objects that may have selected the shape.
/// </summary>
public bool OutOfBand { get; set; }
internal abstract void WriteToXml(FormatXmlWriter writer);
internal virtual bool SafeForExport()
{
return GroupBy == null || GroupBy.IsSafeForExport();
}
internal virtual bool CompatibleWithOldPowerShell()
{
// This is too strict, the GroupBy would just be ignored by the remote
// PowerShell, but that's still wrong.
// OutOfBand is also ignored by old PowerShell, but it's of less importance.
return GroupBy == null;
}
}
/// <summary>
/// Allows specifying a header for groups of related objects being formatted, can
/// be specified on any type of PSControl.
/// </summary>
public sealed class PSControlGroupBy
{
/// <summary>
/// Specifies the property or expression (script block) that controls grouping.
/// </summary>
public DisplayEntry Expression { get; set; }
/// <summary>
/// Optional - used to specify a label for the header of a group.
/// </summary>
public string Label { get; set; }
/// <summary>
/// Optional - used to format the header of a group.
/// </summary>
public CustomControl CustomControl { get; set; }
internal bool IsSafeForExport()
{
return (Expression == null || Expression.SafeForExport()) &&
(CustomControl == null || CustomControl.SafeForExport());
}
internal static PSControlGroupBy Get(GroupBy groupBy)
{
if (groupBy != null)
{
// TODO - groupBy.startGroup.control
var expressionToken = groupBy.startGroup.expression;
return new PSControlGroupBy
{
Expression = new DisplayEntry(expressionToken),
Label = groupBy.startGroup.labelTextToken?.text
};
}
return null;
}
}
/// <summary>
/// One entry in a format display unit, script block or property name.
/// </summary>
public sealed class DisplayEntry
{
/// <summary>Returns the type of this value</summary>
public DisplayEntryValueType ValueType { get; internal set; }
/// <summary>Returns the value as a string</summary>
public string Value { get; internal set; }
internal DisplayEntry() { }
/// <summary>Public constructor for DisplayEntry</summary>
public DisplayEntry(string value, DisplayEntryValueType type)
{
if (string.IsNullOrEmpty(value))
if (value == null || type == DisplayEntryValueType.Property)
throw PSTraceSource.NewArgumentNullException(nameof(value));
Value = value;
ValueType = type;
}
/// <summary/>
public override string ToString()
{
return (ValueType == DisplayEntryValueType.Property ? "property: " : "script: ") + Value;
}
internal DisplayEntry(ExpressionToken expression)
{
Value = expression.expressionValue;
ValueType = expression.isScriptBlock ? DisplayEntryValueType.ScriptBlock : DisplayEntryValueType.Property;
if (string.IsNullOrEmpty(Value))
if (Value == null || ValueType == DisplayEntryValueType.Property)
throw PSTraceSource.NewArgumentNullException("value");
}
internal bool SafeForExport()
{
return ValueType != DisplayEntryValueType.ScriptBlock;
}
}
/// <summary>
/// Each control (table, list, wide, or custom) may have multiple entries. If there are multiple
/// entries, there must be a default entry with no condition, all other entries must have EntrySelectedBy
/// specified. This is useful when you need a single view for grouping or otherwise just selecting the
/// shape of formatting, but need distinct formatting rules for each instance. For example, when
/// listing files, you may want to group based on the parent path, but select different entries
/// depending on if the item is a file or directory.
/// </summary>
public sealed class EntrySelectedBy
{
/// <summary>
/// An optional list of typenames that apply to the entry.
/// </summary>
public List<string> TypeNames { get; set; }
/// <summary>
/// An optional condition that applies to the entry.
/// </summary>
public List<DisplayEntry> SelectionCondition { get; set; }
internal static EntrySelectedBy Get(IEnumerable<string> entrySelectedByType, IEnumerable<DisplayEntry> entrySelectedByCondition)
{
EntrySelectedBy result = null;
if (entrySelectedByType != null || entrySelectedByCondition != null)
{
result = new EntrySelectedBy();
bool isEmpty = true;
if (entrySelectedByType != null)
{
result.TypeNames = new List<string>(entrySelectedByType);
if (result.TypeNames.Count > 0)
isEmpty = false;
}
if (entrySelectedByCondition != null)
{
result.SelectionCondition = new List<DisplayEntry>(entrySelectedByCondition);
if (result.SelectionCondition.Count > 0)
isEmpty = false;
}
if (isEmpty)
return null;
}
return result;
}
internal static EntrySelectedBy Get(List<TypeOrGroupReference> references)
{
EntrySelectedBy result = null;
if (references != null && references.Count > 0)
{
result = new EntrySelectedBy();
foreach (TypeOrGroupReference tr in references)
{
if (tr.conditionToken != null)
{
result.SelectionCondition ??= new List<DisplayEntry>();
result.SelectionCondition.Add(new DisplayEntry(tr.conditionToken));
continue;
}
if (tr is TypeGroupReference)
continue;
result.TypeNames ??= new List<string>();
result.TypeNames.Add(tr.name);
}
}
return result;
}
internal bool SafeForExport()
{
if (SelectionCondition == null)
return true;
foreach (var cond in SelectionCondition)
{
if (!cond.SafeForExport())
return false;
}
return true;
}
internal bool CompatibleWithOldPowerShell()
{
// Old versions of PowerShell know nothing about selection conditions.
return SelectionCondition == null || SelectionCondition.Count == 0;
}
}
/// <summary>
/// Specifies possible alignment enumerations for display cells.
/// </summary>
public enum Alignment
{
/// <summary>
/// Not defined.
/// </summary>
Undefined = 0,
/// <summary>
/// Left of the cell, contents will trail with a ... if exceeded - ex "Display..."
/// </summary>
Left = 1,
/// <summary>
/// Center of the cell.
/// </summary>
Center = 2,
/// <summary>
/// Right of the cell, contents will lead with a ... if exceeded - ex "...456"
/// </summary>
Right = 3,
}
/// <summary>
/// Specifies the type of entry value.
/// </summary>
public enum DisplayEntryValueType
{
/// <summary>
/// The value is a property. Look for a property with the specified name.
/// </summary>
Property = 0,
/// <summary>
/// The value is a scriptblock. Evaluate the script block and fill the entry with the result.
/// </summary>
ScriptBlock = 1,
}
}
|