dahomey-technologies/Dahomey.Cbor

[Question] ObjectMappingRegistry with private fields/properties

Closed this issue · 1 comments

I am adding a custom object mapping registry as advised here #6 like this:

CborOptions.Default.Registry.ObjectMappingRegistry.Register<Tree>(om =>
            {
                om.AutoMap();
                om.ClearMemberMappings();
                om.MapMember(o => o.MyField);
                om.MapMember(o => o.MyField2);
            });

how can I do this with private fields/properties? I do not wan't to add the ObjectMapping in the class itself (athrought I have not tested this, if it would even work).

Like this:

public class Tree
{
    private int _age;
    private string _name;
    ....
}

and:

CborOptions.Default.Registry.ObjectMappingRegistry.Register<ECSignature>(om =>
            {
                om.AutoMap();
                om.ClearMemberMappings();
                om.MapMember(o => o.name); // this does obviously not work
            });

Is there a possibility to add "fields to serialize" via the [CborProperty("name")] and have a List _toSerialize or something like that?