Exemple #1
0
        public override object ReadJson(JsonReader reader, Type objectType,
                                        object existingValue, JsonSerializer serializer)
        {
            if (objectType == typeof(Image))
            {
                string valueString = reader.Value as string;

                if (valueString == null)
                {
                    return(null);
                }
                if (valueString.StartsWith(ATTACHMENT))
                {
                    string     attachmentName = valueString.Replace(ATTACHMENT, "");
                    Attachment attachment     = rev.GetAttachment(attachmentName);
                    if (attachment == null)
                    {
                        return(null);
                    }
                    return(Image.Deserialize(attachment.Content.ToArray()));
                }
                else
                {
                    throw new InvalidCastException();
                }
            }
            return(reader.Value);
        }