Beispiel #1
0
            protected override bool TryDeserialize(ObjectScope scope, TypeModel model, ref ProtoReader.State state, ref object value)
            {
                var serializer = TypeModel.TryGetSerializer <T>(model);

                if (serializer == null)
                {
                    return(false);
                }
                // note this null-check is non-trivial; for value-type T it promotes the null to a default
                T typed = TypeHelper <T> .FromObject(value);

                switch (scope)
                {
                case ObjectScope.LikeRoot:
                    typed = state.ReadAsRoot <T>(typed, serializer);
                    break;

                case ObjectScope.Scalar:
                case ObjectScope.NakedMessage:
                    typed = serializer.Read(ref state, typed);
                    break;

                case ObjectScope.WrappedMessage:
                    typed = state.ReadMessage <T>(default, typed, serializer);
                    break;

                default:
                    return(false);
                }
                value = typed;
                return(true);
            }