anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

MetaType lacks a method returning an enumerable of all the ValueMember instances of the type. #194

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Declare a type, suitable for protobuf-net serialization, yet attribute it 
with the DataContract/DataMember attributes (instead if 
ProtoContract/ProtoMember). This simulates the case when the type to be 
serialized belongs to an assembly, which does not reference protobuf.dll
2. Now try to qualify a property of the type AsReference.

What is the expected output? What do you see instead?
Since ProtoMember is not used, the only alternative is by setting the 
AsReference property on the respective ValueMember object found in the 
respective MetaType instance. The MetaType instance is obtained by:
RuntimeType.Default.Add(typeof(T), true)
I am passing true in the applyDefaultBehavior parameter, because the type is 
attributed with DataContract/DataMember and thus recognized by protobuf-net. 
However, how to get the right ValueMember instance? I have no idea what is the 
fieldNumber and without it I cannot get the right ValueMember instance. What is 
missing is an enumerator of all the available ValueMember instances.

BTW, an enumerator does exist, but it is commented out. Why?

What version of the product are you using? On what operating system?
v2, rev 422

Please provide any additional information below.

Original issue reported on code.google.com by mark.kha...@gmail.com on 25 Jun 2011 at 7:24

GoogleCodeExporter commented 9 years ago
For now, I've added a MemberInfo indexer; does this suffice? The reason the 
`fields` itself isn't exposed is that abuse by simple casting would violate 
some rules; I guess I could copy it to an unrelated array if needed, though.

Let me know if the indexer does the job

Original comment by marc.gravell on 25 Jun 2011 at 9:52

GoogleCodeExporter commented 9 years ago
Yes, indeed it does. Thanks.

The only reservation that I have concerns the requirement to pass a MemberInfo 
instance, rather than a simple string. I understand that it is supposed to feel 
safer, because now the caller has to dig the member with reflection (or through 
the getter expression). But surely you realize that this safety is imaginary, 
but the constraint of requiring a MemberInfo is real and can be pretty annoying.

Original comment by mark.kha...@gmail.com on 26 Jun 2011 at 3:51