/// <summary> /// New object panel with the object explorer. /// </summary> /// <param name="explorer">The panel explorer.</param> public ObjectPanel(ObjectExplorer explorer) : base(explorer) { CurrentLocation = "*"; SortMode = PanelSortMode.Unsorted; }
/// <inheritdoc/> public override Explorer DoOpenFile(OpenFileEventArgs args) { if (args == null) { return(null); } object data = args.File.Data; PSObject psData = PSObject.AsPSObject(data); var type = psData.BaseObject.GetType(); // replace dictionary entry with its value if it is complex if (type == typeof(DictionaryEntry)) { var value = ((DictionaryEntry)psData.BaseObject).Value; if (value != null && !Converter.IsLinearType(value.GetType())) { data = value; psData = PSObject.AsPSObject(value); } } // replace key/value pair with its value if it is complex var typeName = type.FullName; if (typeName.StartsWith("System.Collections.Generic.KeyValuePair`", StringComparison.OrdinalIgnoreCase)) { var value = psData.Properties["Value"].Value; if (value != null && !Converter.IsLinearType(value.GetType())) { data = value; psData = PSObject.AsPSObject(value); } } // case: linear type: ignore, it is useless to open if (Converter.IsLinearType(type)) { args.Result = JobResult.Ignore; return(null); } // case: enumerable (string is excluded by linear type case) IEnumerable asIEnumerable = Cast <IEnumerable> .From(data); if (asIEnumerable != null) { var explorer = new ObjectExplorer(); explorer.AddObjects(asIEnumerable); return(explorer); } // case: group PSPropertyInfo pi = psData.Properties["Group"]; if (pi != null && pi.Value is IEnumerable && !(pi.Value is string)) { var explorer = new ObjectExplorer(); explorer.AddObjects(pi.Value); return(explorer); } // case: WMI if (typeName == "System.Management.ManagementClass") { pi = psData.Properties[Word.Name]; if (pi != null && pi.Value != null) { var values = A.InvokeCode("Get-WmiObject -Class $args[0] -ErrorAction SilentlyContinue", pi.Value.ToString()); var explorer = new ObjectExplorer(); explorer.AddObjects(values); return(explorer); } } // open members return(new MemberExplorer(data)); }
/// <inheritdoc/> public override Explorer DoOpenFile(OpenFileEventArgs args) { if (args == null) return null; object data = args.File.Data; PSObject psData = PSObject.AsPSObject(data); var type = psData.BaseObject.GetType(); // replace dictionary entry with its value if it is complex if (type == typeof(DictionaryEntry)) { var value = ((DictionaryEntry)psData.BaseObject).Value; if (value != null && !Converter.IsLinearType(value.GetType())) { data = value; psData = PSObject.AsPSObject(value); } } // replace key/value pair with its value if it is complex var typeName = type.FullName; if (typeName.StartsWith("System.Collections.Generic.KeyValuePair`", StringComparison.OrdinalIgnoreCase)) { var value = psData.Properties["Value"].Value; if (value != null && !Converter.IsLinearType(value.GetType())) { data = value; psData = PSObject.AsPSObject(value); } } // case: linear type: ignore, it is useless to open if (Converter.IsLinearType(type)) { args.Result = JobResult.Ignore; return null; } // case: enumerable (string is excluded by linear type case) IEnumerable asIEnumerable = Cast<IEnumerable>.From(data); if (asIEnumerable != null) { var explorer = new ObjectExplorer(); explorer.AddObjects(asIEnumerable); return explorer; } // case: group PSPropertyInfo pi = psData.Properties["Group"]; if (pi != null && pi.Value is IEnumerable && !(pi.Value is string)) { var explorer = new ObjectExplorer(); explorer.AddObjects(pi.Value); return explorer; } // case: WMI if (typeName == "System.Management.ManagementClass") { pi = psData.Properties[Word.Name]; if (pi != null && pi.Value != null) { var values = A.InvokeCode("Get-WmiObject -Class $args[0] -ErrorAction SilentlyContinue", pi.Value.ToString()); var explorer = new ObjectExplorer(); explorer.AddObjects(values); return explorer; } } // open members return new MemberExplorer(data); }