c# - Can protobuf-net handle auto read-only properties? -


can protobuf-net handle new auto read-only properties, i.e. auto properties defined single get , no private set?

public class withreadonlyproperty {     public int readonlyproperty { get; }     public withreadonlyproperty(int val) {         readonlyproperty = val;     } } 

when this

runtimetypemodel     .default     .add(typeof (withreadonlyproperty), false)         .add(nameof(withreadonlyproperty.readonlyproperty)); var test = new withreadonlyproperty(12345); using (var output = file.create(@"c:\temp\_readonly.bin")) {     try {         serializer.serialize(output, test);     } catch (exception e) {         console.writeline(e);     } } 

i exception:

system.invalidoperationexception: cannot apply changes property withreadonlyproperty.readonlyproperty    @ protobuf.serializers.propertydecorator.sanitycheck(typemodel model, propertyinfo property, iprotoserializer tail, boolean& writevalue, boolean nonpublic, boolean allowinternal) in c:\dev\protobuf-net\protobuf-net\serializers\propertydecorator.cs:line 46    @ protobuf.serializers.propertydecorator..ctor(typemodel model, type fortype, propertyinfo property, iprotoserializer tail) in c:\dev\protobuf-net\protobuf-net\serializers\propertydecorator.cs:line 32    @ protobuf.meta.valuemember.buildserializer() in c:\dev\protobuf-net\protobuf-net\meta\valuemember.cs:line 375    @ protobuf.meta.metatype.buildserializer() in c:\dev\protobuf-net\protobuf-net\meta\metatype.cs:line 408    @ protobuf.meta.metatype.get_serializer() in c:\dev\protobuf-net\protobuf-net\meta\metatype.cs:line 384    @ protobuf.meta.runtimetypemodel.serialize(int32 key, object value, protowriter dest) in c:\dev\protobuf-net\protobuf-net\meta\runtimetypemodel.cs:line 752    @ protobuf.meta.typemodel.serializecore(protowriter writer, object value) in c:\dev\protobuf-net\protobuf-net\meta\typemodel.cs:line 186    @ protobuf.meta.typemodel.serialize(stream dest, object value, serializationcontext context) in c:\dev\protobuf-net\protobuf-net\meta\typemodel.cs:line 217    @ protobuf.serializer.serialize[t](stream destination, t instance) in c:\dev\protobuf-net\protobuf-net\serializer.cs:line 86     ... 

is possible configure protobuf-net use public constructor? there perhaps other way it? avoid decorating withreadonlyproperty class attributes, if possible.

protobuf can use private constructors, perhaps can make private constructors protobuf use?


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -