Exemplo n.º 1
0
        public void Serialize(ref MessagePackWriter writer, IReactiveProperty <T> value, MessagePackSerializerOptions options)
        {
            var rxProp = value as ReactiveProperty <T>;

            if (rxProp != null)
            {
                ReactivePropertyResolver.Instance.GetFormatterWithVerify <ReactiveProperty <T> >().Serialize(ref writer, rxProp, options);
                return;
            }

            var slimProp = value as ReactivePropertySlim <T>;

            if (slimProp != null)
            {
                ReactivePropertyResolver.Instance.GetFormatterWithVerify <ReactivePropertySlim <T> >().Serialize(ref writer, slimProp, options);
                return;
            }

            if (value == null)
            {
                writer.WriteNil();
            }
            else
            {
                throw new InvalidOperationException("Serializer only supports ReactiveProperty<T> or ReactivePropertySlim<T>. If serialize is ReadOnlyReactiveProperty, should mark [Ignore] and restore on IMessagePackSerializationCallbackReceiver.OnAfterDeserialize. Type:" + value.GetType().Name);
            }
        }
Exemplo n.º 2
0
        public int Serialize(ref byte[] bytes, int offset, IReactiveProperty <T> value, IFormatterResolver formatterResolver)
        {
            var rxProp = value as ReactiveProperty <T>;

            if (rxProp != null)
            {
                return(ReactivePropertyResolver.Instance.GetFormatterWithVerify <ReactiveProperty <T> >().Serialize(ref bytes, offset, rxProp, formatterResolver));
            }

            if (value == null)
            {
                return(MessagePackBinary.WriteNil(ref bytes, offset));
            }
            else
            {
                throw new InvalidOperationException("Serializer only supports ReactiveProperty<T>. If serialize is ReadOnlyReactiveProperty, should mark [Ignore] and restore on IMessagePackSerializationCallbackReceiver.OnAfterDeserialize. Type:" + value.GetType().Name);
            }
        }