As we know, Silverlight does not allow private reflection. However, I have public property with a private setter, which I need for serialization (no problem here) and deserialize (cheating).
I know that nothing in the world would make protobuf-net for this property in Silverlight, it should be done from the client type (or assembly, if the property is made internal).
Is there a protobuf-net scheme for Silverlight that allows? I could force the type to implement some specialized protobuf-net interface (e.g. IProtoSerializable).
Thank.
EDIT
I can offer such a scheme:
[ProtoMember(N, SetterMethod = "DeserializePropValue")] public string property Prop { get { return m_prop; } private set { m_prop = value; } } public void DeserializePropValue(ProtoValue<string> value) { m_prop = value.Value; }
If the ProtoValue type is public, but its constructors are internal, so only the protobuf-net assembly can create instances of this type. And, of course, protobuf-net will not publish a public API for creating ProtoValue objects.
This scheme can only be supported for the Silverlight platform, other platforms will simply invoke a private setter.
What do you think?
EDIT2
I want to note that, of course, you can still get a link to an arbitrary PropValue <T> instance, but this is not accidental, and these are random property rewrites that I want to eliminate. In addition, I want the setter to be non-public, so that it does not appear in the various reflection-based binding mechanisms used in the user interface.
EDIT3
PropValue <T> instances may not be suitable for storage, that is, after the DeserializePropValue method returns, the corresponding PropValue instance will be invalidated. This leaves only one way to offend him, for example:
[ProtoContract] public class Abusee { [ProtoMember(1, SetterMethod = "DeserializePropValue")] public string property Prop { get; private set; } public void DeserializePropValue(ProtoValue<string> value) { m_prop = value.Value; } } [ProtoContract] public class Abuser { private Abusee m_abusee; public Abuser(Abusee abusee, string newPropValue) { m_abusee = abusee; Dummy = newPropValue; Serializer.DeepClone(this); } [ProtoMember(1, SetterMethod = "DeserializeDummyValue")] public string property Dummy { get; private set; } public void DeserializeDummyValue(ProtoValue<string> value) { m_abusee.DeserializePropValue(value); } }
Quite a lot of effort to happen by chance. As for intentional abuse, there is no regression. You can always serialize an object, manipulate binary serialization data, and then deserialize it. Regression is only the ease of abuse. However, my goal is to:
- Error Error Prevention
- Keep the installer not public.
- Avoid the surrogate nightmare.