예제 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (objectType != typeof(TwitterRelationshipConnections) &&
                objectType != typeof(TwitterRelationshipConnections?))
            {
                throw new NotSupportedException();
            }

            if (reader.TokenType == JsonToken.Null)
            {
                if (!reader.ValueType.IsNullableType())
                {
                    throw new NotSupportedException();
                }

                return(null);
            }

            var values = new List <string>();

            while (reader.Read() && reader.TokenType != JsonToken.EndArray)
            {
                values.Add(reader.Value.ToString());
            }

            return(Convert.ToEnum <TwitterRelationshipConnections>(values));
        }
예제 #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            string result = null;

            if (value is TwitterRelationshipConnections)
            {
                var existingValues =
                    Convert.ToString <TwitterRelationshipConnections>((TwitterRelationshipConnections)value);

                var jArray = JArray.FromObject(existingValues.Split(
                                                   new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries));
                result = jArray.ToString();
            }

            writer.WriteValue(result);
        }