Reputation: 2051
In protobuf-net,
Is there a plan to add support for attribute-less POCOs, to avoid the property indexes (ProtoContact) ?
I have not problem to add indexes for each property on DTO.
I create the DTOs automatically with my utility and there is a configuration flag for protobuf members.
The problem is that using RESTful services with ServiceStack,
I share to customers (who work in .Net) 2 assemblies,
the model without any dependencies, nor ServiceStack (not IReturn), nor protobuf-net.
The client.requests, which is a thin wrapper to actual service calls, with some validation,
error handling, etc. Essentially are simplified calls for every service.
This assembly has dependencies on ServiceStack client and Protobuf-net.
But the model is dependency-free, because customers can use it, directly in their business layer.
In this case, I have problem with protobuf-net, not with ServiceStack as IReturn is not mandatory.
Is there any solution about that, to avoid add protobuf indexers ?
Update: thanks to Mark Gravell, his answer here and in previous related question
the solution is the alternative inline attributes,
[XmlType]/[XmlElement(Order=key)] using only System.Xml,
or [DataContract]/[DataMember(Order=key)] using System.Runtime.Serialization.
So the model is dependency free, without references to protobuf-net.
I should have read better about.
[XmlType("Person")]
public class Person
{
[XmlElement(Order = 1)]
public string Name { get; set; }
[XmlElement( Order = 2)]
public string Address { get; set; }
}
thanks
Upvotes: 2
Views: 154
Reputation: 1063338
2 options present themselves:
partial
class, you can create a second partial class file for the same type, and add the attributes there - this is then part of the same type; in particular, note that [ProtoPartialMember(...)]
can be added to a type (multiple times), but describes a member; or if you want less maintenance, [ProtoContract(ImplicitFields=ImplicitFields.AllPublic)]
can be used to let the model take control of the rules (but please read the intellisense remarks on ImplicitFields
before doing this)you can configure the type at runtime, using whatever rules you want, via RuntimeTypeModel
:
var metaType = RuntimeTypeModel.Default.Add(yourType, false);
// TODO: some reflection that decides what members you want to serialize
// and as what keys
foreach(...)
metaType.Add(member, key);
Upvotes: 2