From 487ef6acf51b06bc523aa40ddb130e888932d07c Mon Sep 17 00:00:00 2001 From: Neil MacMullen Date: Sat, 29 Jun 2024 16:13:38 +0100 Subject: [PATCH] Initial work for better edit-kql behaviour --- applications/pskql/PsKqlCmdlet.cs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/applications/pskql/PsKqlCmdlet.cs b/applications/pskql/PsKqlCmdlet.cs index af651d1f..b5aa53d5 100644 --- a/applications/pskql/PsKqlCmdlet.cs +++ b/applications/pskql/PsKqlCmdlet.cs @@ -59,6 +59,10 @@ protected override void EndProcessing() //index and pad with nulls where necessary foreach (var p in item.Properties) { + if (p is PSScriptProperty scr) + { + + } if (badProperties.Contains(p.Name)) continue; //it's important we check the property type _before_ attempting to access the Value @@ -153,12 +157,29 @@ private void AddValue(string columnName, string typeName, object? value, int row //special-casing for properties of type "object" which we turn into strings for the purpose of querying if (typeName == TypeNameHelper.TypeName()) { - typeName = TypeNameHelper.TypeName(); - value = value?.ToString() ?? string.Empty; - } - + if (value != null) + { + WriteDebug($"property '{columnName}' is object so trying to derive type from value"); + typeName = value.GetType().ToString(); + WriteDebug($"prop {columnName} typeof '{value}' is {typeName}"); + if (value is PSObject ps) + { + WriteDebug($"property '{columnName}' is PSObject so trying to derive type from BaseObject"); + typeName = ps.BaseObject.GetType().ToString(); + WriteDebug($"prop {columnName} baseobj typeof '{ps.BaseObject}' is {typeName}"); + value = ps.BaseObject; + } + } + else + { + typeName = TypeNameHelper.TypeName(); + value = value?.ToString() ?? string.Empty; + } + + } + WriteDebug($"Getting builder for {columnName}"); var colBuilder = GetOrCreateBuilder(columnName, typeName); colBuilder.AddAt(value, rowIndex); } -} \ No newline at end of file +}