PropertyInfoのシリアル化はサポートされることになっていますか?そうでない場合、最善の回避策は何ですか?タイプ(サポートされている)をシリアル化してから、その属性でプロパティをルックアップすることが可能であることを私は知っています-ルックアップはおそらく費用がかかると想像してください。
ps PropertyInfoは、DataLoadOptions.LoadWithhttp://msdn.microsoft.com/en-us/library/bb548760.aspxと同様の機能の実装に使用されます。
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ProtoBuf;
[ProtoContract]
public class A
{
[ProtoMember(1)]
public PropertyInfo Property { get; set; }
}
[TestClass]
public class UnitTest
{
[TestMethod]
public void TestMethod1()
{
var value = new A { Property = typeof(string).GetProperty("Length") };
using (var stream = new MemoryStream())
{
// Raises InvalidOperationException
// "No serializer defined for type: System.Reflection.PropertyInfo"
Serializer.Serialize(stream, value);
}
}
}
InvalidOperationException
が発生したときにスタックを呼び出します。
protobuf-net.dll!ProtoBuf.Meta.ValueMember.BuildSerializer() Line 316 C#
protobuf-net.dll!ProtoBuf.Meta.ValueMember.Serializer.get() Line 188 + 0x24 bytes C#
protobuf-net.dll!ProtoBuf.Meta.MetaType.BuildSerializer() Line 421 + 0x1f bytes C#
protobuf-net.dll!ProtoBuf.Meta.MetaType.Serializer.get() Line 344 + 0xe bytes C#
protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Serialize(int key, object value, ProtoBuf.ProtoWriter dest) Line 592 + 0x44 bytes C#
protobuf-net.dll!ProtoBuf.Meta.TypeModel.SerializeCore(ProtoBuf.ProtoWriter writer, object value) Line 178 + 0x14 bytes C#
protobuf-net.dll!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, object value, ProtoBuf.SerializationContext context) Line 209 + 0xe bytes C#
protobuf-net.dll!ProtoBuf.Meta.TypeModel.Serialize(System.IO.Stream dest, object value) Line 193 + 0x10 bytes C#
protobuf-net.dll!ProtoBuf.Serializer.Serialize<TestProtoBufNet.A>(System.IO.Stream destination, TestProtoBufNet.A instance) Line 88 + 0x18 bytes C#
TestProtoBufNet.dll!TestProtoBufNet.UnitTest.TestMethod1() Line 24 + 0x10 bytes C#