Compare commits

...

1 Commits

Author SHA1 Message Date
Jonathon Broughton a945e35a2a fix(Navisworks): include GUIDs and other non-dictionary properties in flat hierarchy (#995)
.NET Build and Publish / build-windows (push) Has been cancelled
.NET Build and Publish / build-linux (push) Has been cancelled
.NET Build and Publish / deploy-installers (push) Has been cancelled
* Flattens pseudo class properties

Handles properties that are not dictionaries by adding them to a "pseudo class properties" category.
This commit flattens those properties into the main dictionary for easier access.

Also filters specific property names like "ClassName" and "DisplayName".

* Avoids processing empty property sets

Prevents processing of objects with no category dictionaries, improving performance and avoiding potential errors.

Changes `bannedNamesForProps` from `List` to `HashSet` for faster lookups.

* Uncomments continue statement.

Re-enables the `continue` statement within the hierarchical property handler.

This ensures that the loop proceeds to the next iteration when a specific condition is met, which prevents unintended behavior.
2025-07-23 08:41:50 +01:00
@@ -9,6 +9,8 @@ public class HierarchicalPropertyHandler(
ClassPropertiesExtractor classPropertiesExtractor
) : BasePropertyHandler(propertySetsExtractor, modelPropertiesExtractor)
{
private string PseudoClassPropertiesKey => "_pseudoClassProperties";
public override Dictionary<string, object?> GetProperties(NAV.ModelItem modelItem)
{
var propertyDict = classPropertiesExtractor.GetClassProperties(modelItem) ?? new Dictionary<string, object?>();
@@ -22,6 +24,7 @@ public class HierarchicalPropertyHandler(
}
ApplyFilteredProperties(propertyDict, propertyCollection);
FlattenPseudoClassProperties(propertyDict);
return propertyDict;
}
@@ -45,6 +48,7 @@ public class HierarchicalPropertyHandler(
{
break;
}
current = current.Parent;
}
@@ -58,6 +62,10 @@ public class HierarchicalPropertyHandler(
)
{
var categoryDictionaries = ProcessPropertySets(item);
if (categoryDictionaries.Count == 0)
{
return;
}
foreach (var kvp in categoryDictionaries)
{
@@ -69,6 +77,19 @@ public class HierarchicalPropertyHandler(
if (kvp.Value is not Dictionary<string, object?> properties)
{
if (!propertyCollection.TryGetValue(PseudoClassPropertiesKey, out var pseudoProperties))
{
pseudoProperties = [];
propertyCollection.Add(PseudoClassPropertiesKey, pseudoProperties);
}
if (!pseudoProperties.TryGetValue(kvp.Key, out var valueSet))
{
valueSet = [];
pseudoProperties.Add(kvp.Key, valueSet);
}
valueSet.Add(kvp.Value);
continue;
}
@@ -79,11 +100,45 @@ public class HierarchicalPropertyHandler(
valueSet = [];
categoryProperties.Add(prop.Key, valueSet);
}
valueSet.Add(prop.Value);
}
}
}
private void FlattenPseudoClassProperties(Dictionary<string, object?> propertyDict)
{
string[] bannedNamesForProps =
[
"ClassName",
"ClassDisplayName",
"DisplayName",
"InstanceGuid",
"Source",
"Source Guid"
];
if (
!propertyDict.TryGetValue(PseudoClassPropertiesKey, out var pseudoPropsObj)
|| pseudoPropsObj is not Dictionary<string, object> pseudoProps
)
{
return;
}
foreach (var prop in pseudoProps.Where(prop => !bannedNamesForProps.Contains(prop.Key)))
{
if (prop.Value == null)
{
continue;
}
propertyDict[prop.Key] = prop.Value;
}
propertyDict.Remove(PseudoClassPropertiesKey);
}
private static void ApplyFilteredProperties(
Dictionary<string, object?> propertyDict,
Dictionary<string, Dictionary<string, HashSet<object?>>> propertyCollection