Closed GoogleCodeExporter closed 8 years ago
Well, it is correct to an extent, but equally since the wire-value and
enum-value are
identical in this case, yes it would be reasonable to accept *either* 300 and
set the
value to (essentially) 300. I'll see what I can do,
Original comment by marc.gravell
on 24 Jan 2010 at 10:18
Original comment by marc.gravell
on 28 Jan 2010 at 7:25
r282
Original comment by marc.gravell
on 28 Jan 2010 at 7:57
now i get the following exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the
target
of an invocation. ---> ProtoBuf.ProtoException: The default enum value
(HttpStatusCode.0) is not defined for the optional property StatusCode
at ProtoBuf.Property.PropertyEnum`2.OnAfterInit()
at ProtoBuf.Property.Property`1.InitPrivate(Int32 tag, DataFormat dataFormat,
Boolean isOptional, MemberInfo member, Delegate getValue, Delegate setValue,
Object
defaultValue)
at ProtoBuf.Property.Property`1.Init(MemberInfo member)
at ProtoBuf.Property.PropertyFactory.Create[T](MemberInfo member)
at ProtoBuf.Serializer`1.Build()
at ProtoBuf.Serializer`1.SerializeChecked(T instance, SerializationContext
destination)
at ProtoBuf.SerializerItemProxy`2.Serialize(TActualClass instance,
SerializationContext destination)
at ProtoBuf.SerializerProxy`1.Serialize(T instance, Stream destination)
at ProtoBuf.Serializer.Serialize[T](Stream destination, T instance)
--- End of inner exception stack trace ---
for my use case, i don't need to parse all possible values of an enum. I can
just
cast it to the underlying type and be done with it. Can I modify the
protobuf-net dll
to do so? or is it under some license?
Original comment by sangeeta...@gmail.com
on 29 Jan 2010 at 2:26
Sorry, I tested with an enum with duplicated values, not specifically
HttpStatusCode;
you could always specify a default value ([DefaultValue(...)] or make it
non-optional
([ProtoMember(..., IsRequired=true)]).
Another cheeky trick is to serialize the integer value directly:
[ProtoMember(24)]
private int StatusSerialized {
get {return (int)Status;}
set {Status = (HttpStatusCode)value;}
}
The source is freely available - you're welcome to modify a local copy.
Original comment by marc.gravell
on 29 Jan 2010 at 7:42
Original issue reported on code.google.com by
sangeeta...@gmail.com
on 22 Jan 2010 at 8:49