diff --git a/docs/articles/framework/Serialization/entry-convert.md b/docs/articles/framework/Serialization/entry-convert.md index 07d81760d..381ba9fd9 100644 --- a/docs/articles/framework/Serialization/entry-convert.md +++ b/docs/articles/framework/Serialization/entry-convert.md @@ -257,7 +257,7 @@ The `EntryEncoderContext` passed to both methods provides: * `Instance` – the containing object (`null` when encoding a type without an instance) > [!IMPORTANT] -> Only `Value`, `SubEntries`, and `Prototypes` of the returned entry are used by `EntryConvert`. Identifier, display name, description, validation, and the read-only flag are merged: the entry is read-only if either the encoder or the member definition marks it as such. +> `Identifier` and `Validation` of the returned entry are always overridden from the member. `DisplayName` and `Description` are used from the encoder if set, otherwise they fall back to the member metadata. The read-only flag is merged: the entry is read-only if either the encoder or the member definition marks it as such. > [!NOTE] > Encoder instances are cached and shared. Implementations must be **stateless and thread-safe** and require a **public parameterless constructor**. diff --git a/src/Moryx/Serialization/EntryConvert/Encoders/EntryEncoderBase.cs b/src/Moryx/Serialization/EntryConvert/Encoders/EntryEncoderBase.cs index 4abc3fa9b..5f7d67c9a 100644 --- a/src/Moryx/Serialization/EntryConvert/Encoders/EntryEncoderBase.cs +++ b/src/Moryx/Serialization/EntryConvert/Encoders/EntryEncoderBase.cs @@ -22,8 +22,9 @@ public abstract class EntryEncoderBase /// /// Encode the value of a member into an . /// Only , and of the - /// returned entry are used. Identifier, display name, description, validation are overriden afterwards from the - /// member. The read-only flag is merged, that is the entry is read-only if either the encoder or the member + /// returned entry are used by default. Identifier and validation are always overridden from the member. + /// Display name and description are used from the encoder if set, otherwise from the member. + /// The read-only flag is merged, that is the entry is read-only if either the encoder or the member /// definition marks it as such. /// /// Current value of the member. Can be null if no instance is available. diff --git a/src/Moryx/Serialization/EntryConvert/EntryConvert.cs b/src/Moryx/Serialization/EntryConvert/EntryConvert.cs index 982f31c22..c7017c57b 100644 --- a/src/Moryx/Serialization/EntryConvert/EntryConvert.cs +++ b/src/Moryx/Serialization/EntryConvert/EntryConvert.cs @@ -268,8 +268,8 @@ private static Entry EncodeWith(EntryEncoderBase encoder, EntryEncoderContext co var encoded = encoder.Encode(value, context); encoded.Identifier = metadata.Identifier; - encoded.DisplayName = metadata.DisplayName; - encoded.Description = metadata.Description; + encoded.DisplayName ??= metadata.DisplayName; + encoded.Description ??= metadata.Description; encoded.Validation = metadata.Validation; return encoded; diff --git a/src/Moryx/Serialization/EntryConvert/Structs/NumericStructEntryEncoder.cs b/src/Moryx/Serialization/EntryConvert/Structs/NumericStructEntryEncoder.cs index 38d438781..5f6899c9a 100644 --- a/src/Moryx/Serialization/EntryConvert/Structs/NumericStructEntryEncoder.cs +++ b/src/Moryx/Serialization/EntryConvert/Structs/NumericStructEntryEncoder.cs @@ -60,16 +60,25 @@ internal abstract class NumericStructEntryEncoder : NumericStructEntryE /// public override Entry Encode(object value, EntryEncoderContext context) { + var hasValue = value is TStruct; + var typedValue = hasValue ? (TStruct)value : default; + var subEntries = EncodeComponents(typedValue, context.Serialization.FormatProvider); + + // Only set display name for actual values; prototypes pass null and should fall back to the member metadata + var displayName = hasValue ? string.Join(", ", subEntries.Select(e => $"{e.Identifier}={e.Value.Current}")) : null; + var typeName = typeof(TStruct).Name; + return new Entry { + DisplayName = displayName, Value = new EntryValue { Type = EntryValueType.Struct, Current = typeName, Default = typeName }, - SubEntries = EncodeComponents(value is TStruct typed ? typed : default, context.Serialization.FormatProvider) + SubEntries = subEntries }; }