using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
namespace Nuclex.Networking.Gallery3.Responses {
/// Custom converter for gallery Date/Time values
public class GalleryDateTimeConverter : JavaScriptConverter {
/// Types for which this converter can be used
/// A list of types supported by the converter
public override IEnumerable SupportedTypes {
get {
return new Type[] {
typeof(DateTime),
typeof(DateTime?)
};
}
}
public override IDictionary Serialize(
object obj, JavaScriptSerializer serializer
) {
/*
Dictionary result = new Dictionary();
if (obj.GetType() == typeof(DateTime)) {
DateTime d = (DateTime)obj;
result[_dateKey] = d.Ticks;
if (d.Kind != DateTimeKind.Unspecified)
result[_kindKey] = d.Kind;
return result;
} else if (obj.GetType() == typeof(DateTime?)) {
DateTime? theDate = (DateTime?)obj;
if (theDate.HasValue) {
result[_dateKey] = theDate.Value.Ticks;
if (theDate.Value.Kind != DateTimeKind.Unspecified)
result[_kindKey] = theDate.Value.Kind;
}
}
return result;
*/
return null;
}
public override object Deserialize(
IDictionary dictionary, Type type, JavaScriptSerializer serializer
) {
/*
if (dictionary.ContainsKey(_dateKey)) {
var d = new DateTime(long.Parse(dictionary[_dateKey].ToString()), DateTimeKind.Unspecified);
if (dictionary.ContainsKey(_kindKey))
d = DateTime.SpecifyKind(d, (DateTimeKind)dictionary[_kindKey]);
return d;
}
*/
return null;
}
private string _dateKey = "d";
private string _kindKey = "k";
}
} // namespace Nuclex.Networking.Gallery3.Responses