-Added JsonConverterAttribute. Can be placed on classes and members. Priority is member attribute -> class attribute -> serializer argument converters

-Added DateTimeFormat to IsoDateTimeConverter to customize format
-Changed IConvertible casting to the ToXXXX methods in JsonSerializer
This commit is contained in:
JamesNK
2008-08-04 09:38:24 +00:00
parent f2aa4a2b40
commit 7cb056d6c7
9 changed files with 356 additions and 41 deletions
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Utilities;
using System.Globalization;
namespace Newtonsoft.Json
{
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false)]
public class JsonConverterAttribute : Attribute
{
private readonly Type _converterType;
public Type ConverterType
{
get { return _converterType; }
}
public JsonConverterAttribute(Type converterType)
{
if (converterType == null)
throw new ArgumentNullException("converterType");
_converterType = converterType;
}
internal JsonConverter CreateJsonConverterInstance()
{
try
{
return (JsonConverter)Activator.CreateInstance(_converterType);
}
catch (Exception ex)
{
throw new Exception("Error creating {0}".FormatWith(CultureInfo.InvariantCulture, _converterType), ex);
}
}
}
}