refactor(dcl): simplify ValueFormatter now that SDK returns native .NET arrays
The LmxProxy client's ExtractArrayValue now returns proper .NET arrays (bool[], int[], DateTime[], etc.) instead of ArrayValue objects. Removed the reflection-based FormatArrayContainer logic — IEnumerable handling is sufficient for all array types.
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
|
||||
namespace ScadaLink.Commons.Types;
|
||||
|
||||
/// <summary>
|
||||
/// Formats attribute values for display. Handles scalar types directly
|
||||
/// and uses reflection to extract array contents from complex types
|
||||
/// (e.g., LmxProxy ArrayValue) rather than showing the type name.
|
||||
/// and converts arrays/collections to comma-separated strings.
|
||||
/// </summary>
|
||||
public static class ValueFormatter
|
||||
{
|
||||
@@ -21,15 +19,6 @@ public static class ValueFormatter
|
||||
if (value is string s) return s;
|
||||
if (value is IFormattable) return value.ToString() ?? "";
|
||||
|
||||
// Check if it's an array-like container with typed sub-collections
|
||||
// (e.g., LmxProxy ArrayValue with BoolValues, Int32Values, etc.)
|
||||
var type = value.GetType();
|
||||
if (type.Namespace?.Contains("LmxProxy") == true || type.Name == "ArrayValue")
|
||||
{
|
||||
return FormatArrayContainer(value, type);
|
||||
}
|
||||
|
||||
// Fallback for IEnumerable (generic collections, arrays)
|
||||
if (value is IEnumerable enumerable)
|
||||
{
|
||||
return string.Join(",", enumerable.Cast<object?>().Select(e => e?.ToString() ?? ""));
|
||||
@@ -37,23 +26,4 @@ public static class ValueFormatter
|
||||
|
||||
return value.ToString() ?? "";
|
||||
}
|
||||
|
||||
private static string FormatArrayContainer(object container, Type type)
|
||||
{
|
||||
// Look for the first non-null property that has a Values list
|
||||
foreach (var prop in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
var propValue = prop.GetValue(container);
|
||||
if (propValue is null) continue;
|
||||
|
||||
// Check if this property has a Values sub-property (e.g., BoolArray.Values)
|
||||
var valuesProp = propValue.GetType().GetProperty("Values");
|
||||
if (valuesProp?.GetValue(propValue) is IEnumerable values)
|
||||
{
|
||||
return string.Join(",", values.Cast<object?>().Select(e => e?.ToString() ?? ""));
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ public class LmxProxyDataConnection : IDataConnection
|
||||
|
||||
/// <summary>
|
||||
/// Normalizes a Vtq value for consumption by the rest of the system.
|
||||
/// Converts LmxProxy ArrayValue objects to comma-separated strings
|
||||
/// so downstream code doesn't need to know about LmxProxy domain types.
|
||||
/// Converts .NET arrays (bool[], int[], DateTime[], etc.) to comma-separated
|
||||
/// display strings so downstream code sees simple string representations.
|
||||
/// </summary>
|
||||
private static object? NormalizeValue(object? value) => value switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user