private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { // use some heuristics to determine the shape if none is specified if (shape == FormatShape.Undefined && parameters == null) { // check first if we have a known shape for a type var typeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames); if (shape == FormatShape.Undefined) { // check if we can have a table: // we want to get the # of properties we are going to display List <PSPropertyExpression> expressionList = PSObjectHelper.GetDefaultPropertySet(so); if (expressionList.Count == 0) { // we failed to get anything from a property set // we just get the first properties out of the first object foreach (MshResolvedExpressionParameterAssociation mrepa in AssociationManager.ExpandAll(so)) { expressionList.Add(mrepa.ResolvedExpression); } } // decide what shape we want for the given number of properties shape = DisplayDataQuery.GetShapeFromPropertyCount(db, expressionList.Count); } } ViewGenerator viewGenerator = null; if (shape == FormatShape.Table) { viewGenerator = new TableViewGenerator(); } else if (shape == FormatShape.List) { viewGenerator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { viewGenerator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { viewGenerator = new ComplexViewGenerator(); } Diagnostics.Assert(viewGenerator != null, "viewGenerator != null"); viewGenerator.Initialize(errorContext, expressionFactory, so, db, parameters); return(viewGenerator); }
private static Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape, PSObject so, TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, FormattingCommandLineParameters parameters) { if ((shape == FormatShape.Undefined) && (parameters == null)) { ConsolidatedString internalTypeNames = so.InternalTypeNames; shape = DisplayDataQuery.GetShapeFromType(expressionFactory, db, internalTypeNames); if (shape == FormatShape.Undefined) { List <MshExpression> defaultPropertySet = PSObjectHelper.GetDefaultPropertySet(so); if (defaultPropertySet.Count == 0) { foreach (MshResolvedExpressionParameterAssociation association in AssociationManager.ExpandAll(so)) { defaultPropertySet.Add(association.ResolvedExpression); } } shape = DisplayDataQuery.GetShapeFromPropertyCount(db, defaultPropertySet.Count); } } Microsoft.PowerShell.Commands.Internal.Format.ViewGenerator generator = null; if (shape == FormatShape.Table) { generator = new TableViewGenerator(); } else if (shape == FormatShape.List) { generator = new ListViewGenerator(); } else if (shape == FormatShape.Wide) { generator = new WideViewGenerator(); } else if (shape == FormatShape.Complex) { generator = new ComplexViewGenerator(); } generator.Initialize(errorContext, expressionFactory, so, db, parameters); return(generator); }
internal static FormatShape GetShapeFromType( MshExpressionFactory expressionFactory, TypeInfoDataBase db, Collection <string> typeNames) { ShapeSelectionDirectives selectionDirectives = db.defaultSettingsSection.shapeSelectionDirectives; TypeMatch typeMatch = new TypeMatch(expressionFactory, db, typeNames); foreach (FormatShapeSelectionOnType shapeSelectionOnType in selectionDirectives.formatShapeSelectionOnTypeList) { if (typeMatch.PerfectMatch(new TypeMatchItem((object)shapeSelectionOnType, shapeSelectionOnType.appliesTo))) { return(shapeSelectionOnType.formatShape); } } if (typeMatch.BestMatch != null) { return(((FormatShapeSelectionBase)typeMatch.BestMatch).formatShape); } Collection <string> typeNames1 = Deserializer.MaskDeserializationPrefix(typeNames); return(typeNames1 != null?DisplayDataQuery.GetShapeFromType(expressionFactory, db, typeNames1) : FormatShape.Undefined); }