DoubleSerializer.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #if !NO_RUNTIME
  2. using System;
  3. using ProtoBuf.Meta;
  4. #if FEAT_IKVM
  5. using Type = IKVM.Reflection.Type;
  6. using IKVM.Reflection;
  7. #else
  8. using System.Reflection;
  9. #endif
  10. namespace ProtoBuf.Serializers
  11. {
  12. sealed class DoubleSerializer : IProtoSerializer
  13. {
  14. #if FEAT_IKVM
  15. readonly Type expectedType;
  16. #else
  17. static readonly Type expectedType = typeof(double);
  18. #endif
  19. public DoubleSerializer(ProtoBuf.Meta.TypeModel model)
  20. {
  21. #if FEAT_IKVM
  22. expectedType = model.MapType(typeof(double));
  23. #endif
  24. }
  25. public Type ExpectedType { get { return expectedType; } }
  26. bool IProtoSerializer.RequiresOldValue { get { return false; } }
  27. bool IProtoSerializer.ReturnsValue { get { return true; } }
  28. #if !FEAT_IKVM
  29. public object Read(object value, ProtoReader source)
  30. {
  31. Helpers.DebugAssert(value == null); // since replaces
  32. return source.ReadDouble();
  33. }
  34. public void Write(object value, ProtoWriter dest)
  35. {
  36. ProtoWriter.WriteDouble((double)value, dest);
  37. }
  38. #endif
  39. #if FEAT_COMPILER
  40. void IProtoSerializer.EmitWrite(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  41. {
  42. ctx.EmitBasicWrite("WriteDouble", valueFrom);
  43. }
  44. void IProtoSerializer.EmitRead(Compiler.CompilerContext ctx, Compiler.Local valueFrom)
  45. {
  46. ctx.EmitBasicRead("ReadDouble", ExpectedType);
  47. }
  48. #endif
  49. }
  50. }
  51. #endif