Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/articles/framework/Serialization/entry-convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ public abstract class EntryEncoderBase
/// <summary>
/// Encode the value of a member into an <see cref="Entry"/>.
/// Only <see cref="Entry.Value"/>, <see cref="Entry.SubEntries"/> and <see cref="Entry.Prototypes"/> 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.
/// </summary>
/// <param name="value">Current value of the member. Can be <c>null</c> if no instance is available.</param>
Expand Down
4 changes: 2 additions & 2 deletions src/Moryx/Serialization/EntryConvert/EntryConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,25 @@ internal abstract class NumericStructEntryEncoder<TStruct> : NumericStructEntryE
/// <inheritdoc />
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
};
}

Expand Down
Loading