internal static object GetAdaptedValue(object obj, string member) { ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); PSMemberInfo memberInfo = null; if ((executionContextFromTLS != null) && (executionContextFromTLS.TypeTable != null)) { ConsolidatedString typeNames = PSObject.GetTypeNames(obj); memberInfo = executionContextFromTLS.TypeTable.GetMembers <PSMemberInfo>(typeNames)[member]; if (memberInfo != null) { memberInfo = CloneMemberInfo(memberInfo, obj); } } PSObject.AdapterSet mappedAdapter = PSObject.GetMappedAdapter(obj, (executionContextFromTLS != null) ? executionContextFromTLS.TypeTable : null); if (memberInfo == null) { memberInfo = mappedAdapter.OriginalAdapter.BaseGetMember <PSMemberInfo>(obj, member); } if ((memberInfo == null) && (mappedAdapter.DotNetAdapter != null)) { memberInfo = mappedAdapter.DotNetAdapter.BaseGetMember <PSMemberInfo>(obj, member); } if (memberInfo != null) { return(memberInfo.Value); } if ((executionContextFromTLS != null) && executionContextFromTLS.IsStrictVersion(2)) { throw new PropertyNotFoundException("PropertyNotFoundStrict", null, ParserStrings.PropertyNotFoundStrict, new object[] { LanguagePrimitives.ConvertTo <string>(member) }); } return(null); }
private ComplexControlEntryDefinition GetActiveComplexControlEntryDefinition(ComplexControlBody complexBody, PSObject so) { ConsolidatedString internalTypeNames = so.InternalTypeNames; TypeMatch match = new TypeMatch(this.expressionFactory, this.db, internalTypeNames); foreach (ComplexControlEntryDefinition definition in complexBody.optionalEntryList) { if (match.PerfectMatch(new TypeMatchItem(definition, definition.appliesTo))) { return(definition); } } if (match.BestMatch != null) { return(match.BestMatch as ComplexControlEntryDefinition); } Collection <string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames); if (typeNames != null) { match = new TypeMatch(this.expressionFactory, this.db, typeNames); foreach (ComplexControlEntryDefinition definition2 in complexBody.optionalEntryList) { if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo))) { return(definition2); } } if (match.BestMatch != null) { return(match.BestMatch as ComplexControlEntryDefinition); } } return(complexBody.defaultEntry); }
private static ConsolidatedString CreateConsolidatedTypeName(ViewDefinition definition, Dictionary<string, List<string>> typeGroupMap) { // Create our "consolidated string" typename which is used as a dictionary key var reflist = definition.appliesTo.referenceList; var consolidatedTypeName = new ConsolidatedString(ConsolidatedString.Empty); foreach (TypeOrGroupReference item in reflist) { // If it's a TypeGroup, we need to look that up and add it's members if (item is TypeGroupReference) { List<string> typesInGroup; if (typeGroupMap.TryGetValue(item.name, out typesInGroup)) { foreach (string typeName in typesInGroup) { consolidatedTypeName.Add(typeName); } } } else { consolidatedTypeName.Add(item.name); } } return consolidatedTypeName; }
private ListControlEntryDefinition GetActiveListControlEntryDefinition(ListControlBody listBody, PSObject so) { ConsolidatedString internalTypeNames = so.InternalTypeNames; TypeMatch match = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, internalTypeNames); foreach (ListControlEntryDefinition definition in listBody.optionalEntryList) { if (match.PerfectMatch(new TypeMatchItem(definition, definition.appliesTo, so))) { return(definition); } } if (match.BestMatch != null) { return(match.BestMatch as ListControlEntryDefinition); } Collection <string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames); if (typeNames != null) { match = new TypeMatch(base.expressionFactory, base.dataBaseInfo.db, typeNames); foreach (ListControlEntryDefinition definition2 in listBody.optionalEntryList) { if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo))) { return(definition2); } } if (match.BestMatch != null) { return(match.BestMatch as ListControlEntryDefinition); } } return(listBody.defaultEntryDefinition); }
private EnumerableExpansion GetExpansionState(PSObject so) { if ((this.parameters != null) && this.parameters.expansion.HasValue) { return(this.parameters.expansion.Value); } ConsolidatedString internalTypeNames = so.InternalTypeNames; return(DisplayDataQuery.GetEnumerableExpansionFromType(this.expressionFactory, this._typeInfoDataBase, internalTypeNames)); }
private static string PSObjectTypeName(PSObject so) { if (so != null) { ConsolidatedString internalTypeNames = so.InternalTypeNames; if (internalTypeNames.Count > 0) { return(internalTypeNames[0]); } } return(""); }
private bool ShouldGenerateView(ConsolidatedString consolidatedTypeName) { foreach (WildcardPattern pattern in _filter) { foreach (var typeName in consolidatedTypeName) { if (pattern.IsMatch(typeName)) { return(true); } } } return(false); }
private bool ProcessOutOfBandObjectInsideDocumentSequence(PSObject so) { if (!this.ShouldProcessOutOfBand) { return(false); } ConsolidatedString internalTypeNames = so.InternalTypeNames; if (this.viewManager.ViewGenerator.IsObjectApplicable(internalTypeNames)) { return(false); } return(this.ProcessOutOfBand(so)); }
internal static object SetAdaptedValue(object obj, string member, object value) { object obj2; try { ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); PSMemberInfo memberInfo = null; if ((executionContextFromTLS != null) && (executionContextFromTLS.TypeTable != null)) { ConsolidatedString typeNames = PSObject.GetTypeNames(obj); memberInfo = executionContextFromTLS.TypeTable.GetMembers <PSMemberInfo>(typeNames)[member]; if (memberInfo != null) { memberInfo = PSGetMemberBinder.CloneMemberInfo(memberInfo, obj); } } PSObject.AdapterSet mappedAdapter = PSObject.GetMappedAdapter(obj, (executionContextFromTLS != null) ? executionContextFromTLS.TypeTable : null); if (memberInfo == null) { memberInfo = mappedAdapter.OriginalAdapter.BaseGetMember <PSMemberInfo>(obj, member); } if ((memberInfo == null) && (mappedAdapter.DotNetAdapter != null)) { memberInfo = mappedAdapter.DotNetAdapter.BaseGetMember <PSMemberInfo>(obj, member); } if (memberInfo == null) { throw InterpreterError.NewInterpreterException(null, typeof(RuntimeException), null, "PropertyAssignmentException", ParserStrings.PropertyNotFound, new object[] { member }); } memberInfo.Value = value; obj2 = value; } catch (SetValueException) { throw; } catch (Exception exception) { ExceptionHandlingOps.ConvertToMethodInvocationException(exception, typeof(SetValueInvocationException), member, 0, null); throw; } return(obj2); }
internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List <ErrorRecord> errors) { ViewGenerator generator; errors = null; ConsolidatedString internalTypeNames = so.InternalTypeNames; ViewDefinition view = DisplayDataQuery.GetOutOfBandView(expressionFactory, db, internalTypeNames); if (view != null) { if (view.mainControl is ComplexControlBody) { generator = new ComplexViewGenerator(); } else { generator = new ListViewGenerator(); } generator.Initialize(errorContext, expressionFactory, db, view, null); } else { if (DefaultScalarTypes.IsTypeInList(internalTypeNames) || IsPropertyLessObject(so)) { return(GenerateOutOfBandObjectAsToString(so)); } if (!useToStringFallback) { return(null); } if (new MshExpression("*").ResolveNames(so).Count <= 0) { return(null); } generator = new ListViewGenerator(); generator.Initialize(errorContext, expressionFactory, so, db, null); } FormatEntryData data = generator.GeneratePayload(so, enumerationLimit); data.outOfBand = true; data.SetStreamTypeFromPSObject(so); errors = generator.ErrorManager.DrainFailedResultList(); return(data); }
private string GetObjectDisplayName(PSObject so) { if (this.complexSpecificParameters.classDisplay == ComplexSpecificParameters.ClassInfoDisplay.none) { return(null); } ConsolidatedString internalTypeNames = so.InternalTypeNames; if (internalTypeNames.Count == 0) { return("PSObject"); } if (this.complexSpecificParameters.classDisplay == ComplexSpecificParameters.ClassInfoDisplay.shortName) { string[] strArray = internalTypeNames[0].Split(new char[] { '.' }); if (strArray.Length > 0) { return(strArray[strArray.Length - 1]); } } return(internalTypeNames[0]); }
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); }
private static int ComputeDefaultAlignment(PSObject so, MshExpression ex) { List <MshExpressionResult> values = ex.GetValues(so); if ((values.Count != 0) && (values[0].Exception == null)) { object result = values[0].Result; if (result != null) { ConsolidatedString internalTypeNames = PSObject.AsPSObject(result).InternalTypeNames; if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(internalTypeNames), "System.String", StringComparison.OrdinalIgnoreCase)) { return(1); } if (DefaultScalarTypes.IsTypeInList(internalTypeNames)) { return(3); } } } return(1); }
internal PSMemberInfo GetPSMemberInfo(DynamicMetaObject target, out BindingRestrictions restrictions, out bool canOptimize, out Type aliasConversionType, HashSet <string> aliases = null, List <BindingRestrictions> aliasRestrictions = null) { lock (this) { aliasConversionType = null; if (this._static) { restrictions = typeof(Type).IsAssignableFrom(target.LimitType) ? BindingRestrictions.GetInstanceRestriction(target.Expression, target.Value) : target.PSGetTypeRestriction(); restrictions = restrictions.Merge(BinderUtils.GetVersionCheck(this, this._version)); canOptimize = true; return(PSObject.GetStaticCLRMember(target.Value, base.Name)); } canOptimize = false; PSMemberInfo info = null; ConsolidatedString types = null; ExecutionContext executionContextFromTLS = LocalPipeline.GetExecutionContextFromTLS(); TypeTable typeTable = (executionContextFromTLS != null) ? executionContextFromTLS.TypeTable : null; if (this._hasTypeTableMember) { types = PSObject.GetTypeNames(target.Value); if (typeTable != null) { info = typeTable.GetMembers <PSMemberInfo>(types)[base.Name]; if (info != null) { canOptimize = true; } } } object obj2 = PSObject.Base(target.Value); PSObject.AdapterSet mappedAdapter = PSObject.GetMappedAdapter(obj2, typeTable); if (info == null) { canOptimize = mappedAdapter.OriginalAdapter.SiteBinderCanOptimize; if (canOptimize) { info = mappedAdapter.OriginalAdapter.BaseGetMember <PSMemberInfo>(obj2, base.Name); } } if (((info == null) && canOptimize) && (mappedAdapter.DotNetAdapter != null)) { info = mappedAdapter.DotNetAdapter.BaseGetMember <PSMemberInfo>(obj2, base.Name); } restrictions = BinderUtils.GetVersionCheck(this, this._version); PSAliasProperty alias = info as PSAliasProperty; if (alias != null) { aliasConversionType = alias.ConversionType; if (aliasRestrictions == null) { aliasRestrictions = new List <BindingRestrictions>(); } info = ResolveAlias(alias, target, aliases, aliasRestrictions); if (info == null) { canOptimize = false; } else { foreach (BindingRestrictions restrictions2 in aliasRestrictions) { restrictions = restrictions.Merge(restrictions2); } } } if (this._hasInstanceMember) { restrictions = restrictions.Merge(this.NotInstanceMember(target)); } restrictions = restrictions.Merge(target.PSGetTypeRestriction()); if (this._hasTypeTableMember) { restrictions = restrictions.Merge(BindingRestrictions.GetInstanceRestriction(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_GetTypeTableFromTLS, new Expression[0]), typeTable)); restrictions = restrictions.Merge(BindingRestrictions.GetExpressionRestriction(Expression.Call(CachedReflectionInfo.PSGetMemberBinder_IsTypeNameSame, target.Expression.Cast(typeof(object)), Expression.Constant(types.Key)))); } return(info); } }
protected override void ProcessRecord() { if ((this.InputObject != null) && (this.InputObject != AutomationNull.Value)) { string fullName; Type type = null; Adapter dotNetStaticAdapter = null; if (this.Static == 1) { dotNetStaticAdapter = PSObject.dotNetStaticAdapter; object baseObject = this.InputObject.BaseObject; type = baseObject as Type; if (type == null) { type = baseObject.GetType(); } fullName = type.FullName; } else { ConsolidatedString internalTypeNames = this.InputObject.InternalTypeNames; if (internalTypeNames.Count != 0) { fullName = internalTypeNames[0]; } else { fullName = "<null>"; } } if (!this.typesAlreadyDisplayed.Contains(fullName)) { PSMemberInfoCollection <PSMemberInfo> infos; this.typesAlreadyDisplayed.Add(fullName, ""); PSMemberTypes memberType = this.memberType; PSMemberViewTypes view = this.view; if (((this.view & PSMemberViewTypes.Extended) == 0) && !typeof(PSMemberSet).ToString().Equals(fullName, StringComparison.OrdinalIgnoreCase)) { memberType ^= PSMemberTypes.MemberSet | PSMemberTypes.ScriptMethod | PSMemberTypes.CodeMethod | PSMemberTypes.PropertySet | PSMemberTypes.ScriptProperty | PSMemberTypes.NoteProperty | PSMemberTypes.CodeProperty | PSMemberTypes.AliasProperty; } if (((this.view & PSMemberViewTypes.Adapted) == 0) && ((this.view & PSMemberViewTypes.Base) == 0)) { memberType ^= PSMemberTypes.ParameterizedProperty | PSMemberTypes.Method | PSMemberTypes.Property; } if (((this.view & PSMemberViewTypes.Base) == PSMemberViewTypes.Base) && (this.InputObject.InternalBaseDotNetAdapter == null)) { view |= PSMemberViewTypes.Adapted; } if (this.Static == 1) { infos = dotNetStaticAdapter.BaseGetMembers <PSMemberInfo>(type); } else { Collection <CollectionEntry <PSMemberInfo> > memberCollection = PSObject.GetMemberCollection(view); infos = new PSMemberInfoIntegratingCollection <PSMemberInfo>(this.InputObject, memberCollection); } foreach (string str3 in this.Name) { ReadOnlyPSMemberInfoCollection <PSMemberInfo> infos2 = infos.Match(str3, memberType, this.matchOptions); MemberDefinition[] array = new MemberDefinition[infos2.Count]; int index = 0; foreach (PSMemberInfo info in infos2) { if (this.Force == 0) { PSMethod method = info as PSMethod; if ((method != null) && method.IsSpecial) { continue; } } array[index] = new MemberDefinition(fullName, info.Name, info.MemberType, info.ToString()); index++; } Array.Sort <MemberDefinition>(array, 0, index, new MemberComparer()); for (int i = 0; i < index; i++) { base.WriteObject(array[i]); } } } } }
private List <TableRowItemDefinition> GetActiveTableRowDefinition(TableControlBody tableBody, PSObject so) { if (tableBody.optionalDefinitionList.Count == 0) { return(tableBody.defaultDefinition.rowItemDefinitionList); } TableRowDefinition bestMatch = null; ConsolidatedString internalTypeNames = so.InternalTypeNames; TypeMatch match = new TypeMatch(this.expressionFactory, this.typeInfoDatabase, internalTypeNames); foreach (TableRowDefinition definition2 in tableBody.optionalDefinitionList) { if (match.PerfectMatch(new TypeMatchItem(definition2, definition2.appliesTo))) { bestMatch = definition2; break; } } if (bestMatch == null) { bestMatch = match.BestMatch as TableRowDefinition; } if (bestMatch == null) { Collection <string> typeNames = Deserializer.MaskDeserializationPrefix(internalTypeNames); if (typeNames != null) { match = new TypeMatch(this.expressionFactory, this.typeInfoDatabase, typeNames); foreach (TableRowDefinition definition3 in tableBody.optionalDefinitionList) { if (match.PerfectMatch(new TypeMatchItem(definition3, definition3.appliesTo))) { bestMatch = definition3; break; } } if (bestMatch == null) { bestMatch = match.BestMatch as TableRowDefinition; } } } if (bestMatch == null) { return(tableBody.defaultDefinition.rowItemDefinitionList); } List <TableRowItemDefinition> list = new List <TableRowItemDefinition>(); int num = 0; foreach (TableRowItemDefinition definition4 in bestMatch.rowItemDefinitionList) { if (definition4.formatTokenList.Count == 0) { list.Add(tableBody.defaultDefinition.rowItemDefinitionList[num]); } else { list.Add(definition4); } num++; } return(list); }
internal void Initialize(TerminatingErrorContext errorContext, MshExpressionFactory expressionFactory, TypeInfoDataBase db, PSObject so, FormatShape shape, FormattingCommandLineParameters parameters) { ViewDefinition view = null; try { DisplayDataQuery.SetTracer(formatViewBindingTracer); ConsolidatedString internalTypeNames = so.InternalTypeNames; if (shape == FormatShape.Undefined) { using (formatViewBindingTracer.TraceScope("FINDING VIEW TYPE: {0}", new object[] { PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, null); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } else if ((parameters != null) && (parameters.mshParameterList.Count > 0)) { this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); } else { if ((parameters != null) && !string.IsNullOrEmpty(parameters.viewName)) { using (formatViewBindingTracer.TraceScope("FINDING VIEW NAME: {0} TYPE: {1}", new object[] { parameters.viewName, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, parameters.viewName); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); return; } formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); ProcessUnknownViewName(errorContext, parameters.viewName, so, db, shape); } using (formatViewBindingTracer.TraceScope("FINDING VIEW {0} TYPE: {1}", new object[] { shape, PSObjectTypeName(so) })) { view = DisplayDataQuery.GetViewByShapeAndType(expressionFactory, db, shape, internalTypeNames, null); } if (view != null) { this.viewGenerator = SelectViewGeneratorFromViewDefinition(errorContext, expressionFactory, db, view, parameters); formatViewBindingTracer.WriteLine("An applicable view has been found", new object[0]); PrepareViewForRemoteObjects(this.ViewGenerator, so); } else { formatViewBindingTracer.WriteLine("No applicable view has been found", new object[0]); this.viewGenerator = SelectViewGeneratorFromProperties(shape, so, errorContext, expressionFactory, db, parameters); PrepareViewForRemoteObjects(this.ViewGenerator, so); } } } finally { DisplayDataQuery.ResetTracer(); } }
private bool ShouldGenerateView(ConsolidatedString consolidatedTypeName) { foreach (WildcardPattern pattern in _filter) { foreach (var typeName in consolidatedTypeName) { if (pattern.IsMatch(typeName)) { return true; } } } return false; }