internal override object GetValue(PSObject liveObject)
        {
            try
            {
                PSPropertyInfo propertyInfo = liveObject.Properties[_liveObjectPropertyName];
                if (propertyInfo == null)
                {
                    return(null);
                }

                // The live object has the liveObjectPropertyName property.
                object      liveObjectValue = propertyInfo.Value;
                ICollection collectionValue = liveObjectValue as ICollection;
                if (collectionValue != null)
                {
                    liveObjectValue = _parentCmdlet.ConvertToString(PSObjectHelper.AsPSObject(propertyInfo.Value));
                }
                else
                {
                    PSObject psObjectValue = liveObjectValue as PSObject;
                    if (psObjectValue != null)
                    {
                        // Since PSObject implements IComparable there is a need to verify if its BaseObject actually implements IComparable.
                        if (psObjectValue.BaseObject is IComparable)
                        {
                            liveObjectValue = psObjectValue;
                        }
                        else
                        {
                            // Use the String type as default.
                            liveObjectValue = _parentCmdlet.ConvertToString(psObjectValue);
                        }
                    }
                }

                return(ColumnInfo.LimitString(liveObjectValue));
            }
            catch (GetValueException)
            {
                // ignore
            }
            catch (ExtendedTypeSystemException)
            {
                // ignore
            }

            return(null);
        }
Exemplo n.º 2
0
        private void AddExtraProperties(PSObject staleObject, PSObject liveObject)
        {
            // Add 3 extra properties, so that the stale PSObject has meaningful info in the Hetero-type header view.
            staleObject.Properties.Add(new PSNoteProperty(OutWindowProxy.IndexPropertyName, _index++));
            staleObject.Properties.Add(new PSNoteProperty(OutWindowProxy.OriginalTypePropertyName, liveObject.BaseObject.GetType().FullName));
            staleObject.Properties.Add(new PSNoteProperty(OutWindowProxy.OriginalObjectPropertyName, liveObject));

            // Convert the LivePSObject to a string preserving PowerShell formatting.
            staleObject.Properties.Add(new PSNoteProperty(OutWindowProxy.ToStringValuePropertyName,
                                                          _parentCmdlet.ConvertToString(liveObject)));
        }
 internal override object GetValue(PSObject liveObject)
 {
     // Convert to a string preserving PowerShell formatting.
     return(ColumnInfo.LimitString(_parentCmdlet.ConvertToString(liveObject)));
 }