diff --git a/Src/Lib/NUnitLite.dll b/Src/Lib/NUnitLite.dll new file mode 100644 index 00000000..3cc074fd Binary files /dev/null and b/Src/Lib/NUnitLite.dll differ diff --git a/Src/Newtonsoft.Json.Compact.sln b/Src/Newtonsoft.Json.Compact.sln new file mode 100644 index 00000000..303a9a4e --- /dev/null +++ b/Src/Newtonsoft.Json.Compact.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Compact", "Newtonsoft.Json\Newtonsoft.Json.Compact.csproj", "{256AA604-F61B-4B6D-8D51-C8E6AB11E435}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lib", "Lib", "{9ACB12BA-F27A-4BC4-A8C7-9A5B0DD02DF2}" + ProjectSection(SolutionItems) = preProject + Lib\NUnitLite.dll = Lib\NUnitLite.dll + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Newtonsoft.Json.Tests.Compact", "Newtonsoft.Json.Tests\Newtonsoft.Json.Tests.Compact.csproj", "{32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Debug|Any CPU.Build.0 = Debug|Any CPU + {256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.ActiveCfg = Release|Any CPU + {256AA604-F61B-4B6D-8D51-C8E6AB11E435}.Release|Any CPU.Build.0 = Release|Any CPU + {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Src/Newtonsoft.Json.Tests/JavaScriptConvertTest.cs b/Src/Newtonsoft.Json.Tests/JavaScriptConvertTest.cs index 0f65a8f0..395e2c68 100644 --- a/Src/Newtonsoft.Json.Tests/JavaScriptConvertTest.cs +++ b/Src/Newtonsoft.Json.Tests/JavaScriptConvertTest.cs @@ -260,8 +260,10 @@ now brown cow?", '"', true); int i = JavaScriptConvert.DeserializeObject("1"); Assert.AreEqual(1, i); +#if !PocketPC DateTimeOffset d = JavaScriptConvert.DeserializeObject(@"""\/Date(-59011455539000+0000)\/"""); Assert.AreEqual(new DateTimeOffset(new DateTime(100, 1, 1, 1, 1, 1, DateTimeKind.Utc)), d); +#endif bool b = JavaScriptConvert.DeserializeObject("true"); Assert.AreEqual(true, b); diff --git a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs index 117425f6..6ad453e4 100644 --- a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs @@ -36,7 +36,9 @@ using System.Collections.ObjectModel; using Newtonsoft.Json.Linq; using System.Linq; using Newtonsoft.Json.Converters; +#if !PocketPC using System.Runtime.Serialization.Json; +#endif using Newtonsoft.Json.Utilities; using System.Globalization; using System.ComponentModel; @@ -742,6 +744,7 @@ keyword such as type of business."" Assert.AreEqual("Large", deserializedProductShort.Sizes[2]); } +#if !PocketPC [Test] public void Unicode() { @@ -781,6 +784,7 @@ keyword such as type of business."" result = JavaScriptConvert.SerializeObject(testDates); Assert.AreEqual(expected, result); } +#endif [Test] public void DateTimeOffset() @@ -1319,5 +1323,13 @@ keyword such as type of business."" new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); Assert.AreEqual(@"{}", json); } + + [Test] + public void DeserializeStringDate() + { + string dateText = @"""\/Date(1221644506800-0700)\/"""; + + + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs index fee72e56..d35b5f5a 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/JTokenTests.cs @@ -159,7 +159,11 @@ namespace Newtonsoft.Json.Tests.Linq public void Casting() { Assert.AreEqual(new DateTime(2000, 12, 20), (DateTime)new JValue(new DateTime(2000, 12, 20))); +#if !PocketPC Assert.AreEqual(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero), (DateTimeOffset)new JValue(new DateTimeOffset(2000, 12, 20, 23, 50, 10, TimeSpan.Zero))); + Assert.AreEqual(null, (DateTimeOffset?)new JValue((DateTimeOffset?)null)); + Assert.AreEqual(null, (DateTimeOffset?)(JValue)null); +#endif Assert.AreEqual(true, (bool)new JValue(true)); Assert.AreEqual(true, (bool?)new JValue(true)); Assert.AreEqual(null, (bool?)((JValue)null)); @@ -170,9 +174,7 @@ namespace Newtonsoft.Json.Tests.Linq Assert.AreEqual(null, (int?)new JValue((int?)null)); Assert.AreEqual(null, (int?)(JValue)null); Assert.AreEqual(null, (DateTime?)new JValue((DateTime?)null)); - Assert.AreEqual(null, (DateTimeOffset?)new JValue((DateTimeOffset?)null)); Assert.AreEqual(null, (DateTime?)(JValue)null); - Assert.AreEqual(null, (DateTimeOffset?)(JValue)null); Assert.AreEqual(null, (short?)new JValue((short?)null)); Assert.AreEqual(null, (short?)(JValue)null); Assert.AreEqual(null, (float?)new JValue((float?)null)); diff --git a/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj new file mode 100644 index 00000000..bf7ebc84 --- /dev/null +++ b/Src/Newtonsoft.Json.Tests/Newtonsoft.Json.Tests.Compact.csproj @@ -0,0 +1,103 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {32EA9694-4FB3-43E9-A6AD-050F1D35EA0A} + Library + Properties + Newtonsoft.Json.Tests.Compact + Newtonsoft.Json.Tests.Compact + {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + PocketPC + b2c48bd2-963d-4549-9169-1fa021dce484 + 5.2 + Newtonsoft.Json.Tests.Compact + v3.5 + Windows Mobile 6 Professional SDK + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE;$(PlatformFamilyName) + true + true + prompt + 512 + 4 + Off + + + pdbonly + true + bin\Release\ + TRACE;$(PlatformFamilyName) + true + true + prompt + 512 + 4 + Off + + + + + False + ..\Lib\NUnitLite.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {256AA604-F61B-4B6D-8D51-C8E6AB11E435} + Newtonsoft.Json.Compact + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs index 0004545b..2f117300 100644 --- a/Src/Newtonsoft.Json.Tests/PerformanceTests.cs +++ b/Src/Newtonsoft.Json.Tests/PerformanceTests.cs @@ -1,4 +1,4 @@ -#if !SILVERLIGHT +#if !SILVERLIGHT && !PocketPC using System; using System.Collections.Generic; using System.Globalization; diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index 4999ec2d..5dfbc24e 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -6,10 +6,12 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. -#if !SILVERLIGHT -[assembly: AssemblyTitle("Newtonsoft Json.NET Tests")] -#else +#if SILVERLIGHT [assembly: AssemblyTitle("Newtonsoft Json.NET Tests Silverlight")] +#elif PocketPC +[assembly: AssemblyTitle("Newtonsoft Json.NET Tests Compact")] +#else +[assembly: AssemblyTitle("Newtonsoft Json.NET Tests")] #endif [assembly: AssemblyDescription("")] @@ -38,4 +40,6 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("3.0.0.0")] +#if !PocketPC [assembly: AssemblyFileVersion("3.0.0.0")] +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs b/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs index 807e2cf8..054f3203 100644 --- a/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs +++ b/Src/Newtonsoft.Json/Converters/HtmlColorConverter.cs @@ -23,7 +23,7 @@ // OTHER DEALINGS IN THE SOFTWARE. #endregion -#if !SILVERLIGHT +#if !SILVERLIGHT && !PocketPC using System; using System.Collections.Generic; using System.Text; diff --git a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs index fe9f7526..7e4ea01a 100644 --- a/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/IsoDateTimeConverter.cs @@ -120,8 +120,12 @@ namespace Newtonsoft.Json.Converters /// public override bool CanConvert(Type objectType) { - return (typeof(DateTime).IsAssignableFrom(objectType) - || typeof(DateTimeOffset).IsAssignableFrom(objectType)); + if (typeof(DateTime).IsAssignableFrom(objectType)) + return true; + if (typeof(DateTimeOffset).IsAssignableFrom(objectType)) + return true; + + return false; } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs b/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs index 12b8cd1a..e20b2806 100644 --- a/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/JavaScriptDateTimeConverter.cs @@ -79,8 +79,12 @@ namespace Newtonsoft.Json.Converters /// public override bool CanConvert(Type objectType) { - return (typeof(DateTime).IsAssignableFrom(objectType) - || typeof(DateTimeOffset).IsAssignableFrom(objectType)); + if (typeof(DateTime).IsAssignableFrom(objectType)) + return true; + if (typeof(DateTimeOffset).IsAssignableFrom(objectType)) + return true; + + return false; } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs index 34bd47f0..6a934ab8 100644 --- a/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs +++ b/Src/Newtonsoft.Json/Converters/XmlNodeConverter.cs @@ -27,7 +27,6 @@ using System; using System.Collections.Generic; using System.Text; -using System.Drawing; using System.Xml; using Newtonsoft.Json.Utilities; using System.Linq; diff --git a/Src/Newtonsoft.Json/DateTimeOffset.cs b/Src/Newtonsoft.Json/DateTimeOffset.cs new file mode 100644 index 00000000..5670fd05 --- /dev/null +++ b/Src/Newtonsoft.Json/DateTimeOffset.cs @@ -0,0 +1,558 @@ +#if PocketPC +using System.Globalization; +using System.Runtime.InteropServices; +using System.Runtime.Serialization; +using System.Security.Permissions; +using System; + +namespace Newtonsoft.Json +{ + public struct DateTimeOffset : IComparable, IFormattable, IComparable, IEquatable + { + private DateTime _dateTime; + private short _offsetMinutes; + internal const long MaxOffset = 0x7558bdb000L; + public static readonly DateTimeOffset MaxValue; + internal const long MinOffset = -504000000000L; + public static readonly DateTimeOffset MinValue; + + static DateTimeOffset() + { + MinValue = new DateTimeOffset(0L, TimeSpan.Zero); + MaxValue = new DateTimeOffset(0x2bca2875f4373fffL, TimeSpan.Zero); + } + + public DateTimeOffset(System.DateTime dateTime) + { + TimeSpan utcOffset; + if (dateTime.Kind != DateTimeKind.Utc) + { + utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(dateTime); + } + else + { + utcOffset = new TimeSpan(0L); + } + this._offsetMinutes = ValidateOffset(utcOffset); + this._dateTime = ValidateDate(dateTime, utcOffset); + } + + public DateTimeOffset(System.DateTime dateTime, TimeSpan offset) + { + if (dateTime.Kind == DateTimeKind.Local) + { + if (offset != TimeZone.CurrentTimeZone.GetUtcOffset(dateTime)) + { + throw new ArgumentException("The UTC Offset of the local dateTime parameter does not match the offset argument.", "offset"); + } + } + else if ((dateTime.Kind == DateTimeKind.Utc) && (offset != TimeSpan.Zero)) + { + throw new ArgumentException("The UTC Offset for Utc DateTime instances must be 0.", "offset"); + } + this._offsetMinutes = ValidateOffset(offset); + this._dateTime = ValidateDate(dateTime, offset); + } + + public DateTimeOffset(long ticks, TimeSpan offset) + { + this._offsetMinutes = ValidateOffset(offset); + System.DateTime dateTime = new System.DateTime(ticks); + this._dateTime = ValidateDate(dateTime, offset); + } + + public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, TimeSpan offset) + { + this._offsetMinutes = ValidateOffset(offset); + this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second), offset); + } + + public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeSpan offset) + { + this._offsetMinutes = ValidateOffset(offset); + this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second, millisecond), offset); + } + + public DateTimeOffset(int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar, TimeSpan offset) + { + this._offsetMinutes = ValidateOffset(offset); + this._dateTime = ValidateDate(new System.DateTime(year, month, day, hour, minute, second, millisecond, calendar), offset); + } + + public DateTimeOffset Add(TimeSpan timeSpan) + { + return new DateTimeOffset(this.ClockDateTime.Add(timeSpan), this.Offset); + } + + public DateTimeOffset AddDays(double days) + { + return new DateTimeOffset(this.ClockDateTime.AddDays(days), this.Offset); + } + + public DateTimeOffset AddHours(double hours) + { + return new DateTimeOffset(this.ClockDateTime.AddHours(hours), this.Offset); + } + + public DateTimeOffset AddMilliseconds(double milliseconds) + { + return new DateTimeOffset(this.ClockDateTime.AddMilliseconds(milliseconds), this.Offset); + } + + public DateTimeOffset AddMinutes(double minutes) + { + return new DateTimeOffset(this.ClockDateTime.AddMinutes(minutes), this.Offset); + } + + public DateTimeOffset AddMonths(int months) + { + return new DateTimeOffset(this.ClockDateTime.AddMonths(months), this.Offset); + } + + public DateTimeOffset AddSeconds(double seconds) + { + return new DateTimeOffset(this.ClockDateTime.AddSeconds(seconds), this.Offset); + } + + public DateTimeOffset AddTicks(long ticks) + { + return new DateTimeOffset(this.ClockDateTime.AddTicks(ticks), this.Offset); + } + + public DateTimeOffset AddYears(int years) + { + return new DateTimeOffset(this.ClockDateTime.AddYears(years), this.Offset); + } + + public static int Compare(DateTimeOffset first, DateTimeOffset second) + { + return System.DateTime.Compare(first.UtcDateTime, second.UtcDateTime); + } + + public int CompareTo(DateTimeOffset other) + { + System.DateTime utcDateTime = other.UtcDateTime; + System.DateTime time2 = this.UtcDateTime; + if (time2 > utcDateTime) + { + return 1; + } + if (time2 < utcDateTime) + { + return -1; + } + return 0; + } + + public bool Equals(DateTimeOffset other) + { + return this.UtcDateTime.Equals(other.UtcDateTime); + } + + public override bool Equals(object obj) + { + if (obj is DateTimeOffset) + { + DateTimeOffset offset = (DateTimeOffset)obj; + return this.UtcDateTime.Equals(offset.UtcDateTime); + } + return false; + } + + public static bool Equals(DateTimeOffset first, DateTimeOffset second) + { + return System.DateTime.Equals(first.UtcDateTime, second.UtcDateTime); + } + + public bool EqualsExact(DateTimeOffset other) + { + return (((this.ClockDateTime == other.ClockDateTime) && (this.Offset == other.Offset)) && (this.ClockDateTime.Kind == other.ClockDateTime.Kind)); + } + + public static DateTimeOffset FromFileTime(long fileTime) + { + return new DateTimeOffset(System.DateTime.FromFileTime(fileTime)); + } + + public override int GetHashCode() + { + return this.UtcDateTime.GetHashCode(); + } + + public static DateTimeOffset operator +(DateTimeOffset dateTimeTz, TimeSpan timeSpan) + { + return new DateTimeOffset(dateTimeTz.ClockDateTime + timeSpan, dateTimeTz.Offset); + } + + public static bool operator ==(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime == right.UtcDateTime); + } + + public static bool operator >(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime > right.UtcDateTime); + } + + public static bool operator >=(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime >= right.UtcDateTime); + } + + public static implicit operator DateTimeOffset(System.DateTime dateTime) + { + return new DateTimeOffset(dateTime); + } + + public static bool operator !=(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime != right.UtcDateTime); + } + + public static bool operator <(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime < right.UtcDateTime); + } + + public static bool operator <=(DateTimeOffset left, DateTimeOffset right) + { + return (left.UtcDateTime <= right.UtcDateTime); + } + + public static TimeSpan operator -(DateTimeOffset left, DateTimeOffset right) + { + return (TimeSpan)(left.UtcDateTime - right.UtcDateTime); + } + + public static DateTimeOffset operator -(DateTimeOffset dateTimeTz, TimeSpan timeSpan) + { + return new DateTimeOffset(dateTimeTz.ClockDateTime - timeSpan, dateTimeTz.Offset); + } + + public static DateTimeOffset Parse(string input) + { + return new DateTimeOffset(DateTime.Parse(input, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None)); + } + + public static DateTimeOffset Parse(string input, IFormatProvider formatProvider) + { + return Parse(input, formatProvider, DateTimeStyles.None); + } + + public static DateTimeOffset Parse(string input, IFormatProvider formatProvider, DateTimeStyles styles) + { + styles = ValidateStyles(styles, "styles"); + return new DateTimeOffset(DateTime.Parse(input, DateTimeFormatInfo.GetInstance(formatProvider), styles)); + } + + public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider) + { + return ParseExact(input, format, formatProvider, DateTimeStyles.None); + } + + public static DateTimeOffset ParseExact(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles) + { + styles = ValidateStyles(styles, "styles"); + return new DateTimeOffset(DateTime.ParseExact(input, format, DateTimeFormatInfo.GetInstance(formatProvider), styles)); + } + + public static DateTimeOffset ParseExact(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles) + { + styles = ValidateStyles(styles, "styles"); + return new DateTimeOffset(DateTime.ParseExact(input, formats, DateTimeFormatInfo.GetInstance(formatProvider), styles)); + } + + public TimeSpan Subtract(DateTimeOffset value) + { + return this.UtcDateTime.Subtract(value.UtcDateTime); + } + + public DateTimeOffset Subtract(TimeSpan value) + { + return new DateTimeOffset(this.ClockDateTime.Subtract(value), this.Offset); + } + + int IComparable.CompareTo(object obj) + { + if (obj == null) + { + return 1; + } + if (!(obj is DateTimeOffset)) + { + throw new ArgumentException("Object must be of type DateTimeOffset."); + } + DateTimeOffset offset = (DateTimeOffset)obj; + System.DateTime utcDateTime = offset.UtcDateTime; + System.DateTime time2 = this.UtcDateTime; + if (time2 > utcDateTime) + { + return 1; + } + if (time2 < utcDateTime) + { + return -1; + } + return 0; + } + + public long ToFileTime() + { + return this.UtcDateTime.ToFileTime(); + } + + public DateTimeOffset ToLocalTime() + { + return new DateTimeOffset(this.UtcDateTime.ToLocalTime()); + } + + public DateTimeOffset ToOffset(TimeSpan offset) + { + System.DateTime time = this._dateTime + offset; + return new DateTimeOffset(time.Ticks, offset); + } + + //public override string ToString() + //{ + // return DateTimeFormat.Format(this.ClockDateTime, null, DateTimeFormatInfo.CurrentInfo, this.Offset); + //} + + //public string ToString(IFormatProvider formatProvider) + //{ + // return DateTimeFormat.Format(this.ClockDateTime, null, DateTimeFormatInfo.GetInstance(formatProvider), this.Offset); + //} + + //public string ToString(string format) + //{ + // return DateTimeFormat.Format(this.ClockDateTime, format, DateTimeFormatInfo.CurrentInfo, this.Offset); + //} + + //public string ToString(string format, IFormatProvider formatProvider) + //{ + // return DateTimeFormat.Format(this.ClockDateTime, format, DateTimeFormatInfo.GetInstance(formatProvider), this.Offset); + //} + + public string ToString(string format, IFormatProvider formatProvider) + { + if (!string.IsNullOrEmpty(format)) + { + format = format.Replace("K", "zzz"); + format = format.Replace("zzz", Offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + Offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture)); + format = format.Replace("zz", Offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture)); + format = format.Replace("z", Offset.Hours.ToString("+0;-0", CultureInfo.InvariantCulture)); + } + + return ClockDateTime.ToString(format, formatProvider); + } + + public DateTimeOffset ToUniversalTime() + { + return new DateTimeOffset(this.UtcDateTime); + } + + private static System.DateTime ValidateDate(System.DateTime dateTime, TimeSpan offset) + { + long ticks = dateTime.Ticks - offset.Ticks; + if ((ticks < 0L) || (ticks > 0x2bca2875f4373fffL)) + { + throw new ArgumentOutOfRangeException("offset", "The UTC time represented when the offset is applied must be between year 0 and 10,000."); + } + return new System.DateTime(ticks, DateTimeKind.Unspecified); + } + + private static short ValidateOffset(TimeSpan offset) + { + long ticks = offset.Ticks; + if ((ticks % 0x23c34600L) != 0L) + { + throw new ArgumentException("Offset must be specified in whole minutes.", "offset"); + } + if ((ticks < -504000000000L) || (ticks > 0x7558bdb000L)) + { + throw new ArgumentOutOfRangeException("offset", "Offset must be within plus or minus 14 hours."); + } + return (short)(offset.Ticks / 0x23c34600L); + } + + private static DateTimeStyles ValidateStyles(DateTimeStyles style, string parameterName) + { + if ((style & ~(DateTimeStyles.RoundtripKind | DateTimeStyles.AssumeUniversal | DateTimeStyles.AssumeLocal | DateTimeStyles.AdjustToUniversal | DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AllowWhiteSpaces)) != DateTimeStyles.None) + { + throw new ArgumentException("An undefined DateTimeStyles value is being used.", parameterName); + } + if (((style & DateTimeStyles.AssumeLocal) != DateTimeStyles.None) && ((style & DateTimeStyles.AssumeUniversal) != DateTimeStyles.None)) + { + throw new ArgumentException("The DateTimeStyles values AssumeLocal and AssumeUniversal cannot be used together.", parameterName); + } + if ((style & DateTimeStyles.NoCurrentDateDefault) != DateTimeStyles.None) + { + throw new ArgumentException("The DateTimeStyles value 'NoCurrentDateDefault' is not allowed when parsing DateTimeOffset.", parameterName); + } + style &= ~DateTimeStyles.RoundtripKind; + style &= ~DateTimeStyles.AssumeLocal; + return style; + } + + private System.DateTime ClockDateTime + { + get + { + System.DateTime time = this._dateTime + this.Offset; + return new System.DateTime(time.Ticks, DateTimeKind.Unspecified); + } + } + + public System.DateTime Date + { + get + { + return this.ClockDateTime.Date; + } + } + + public System.DateTime DateTime + { + get + { + return this.ClockDateTime; + } + } + + public int Day + { + get + { + return this.ClockDateTime.Day; + } + } + + public System.DayOfWeek DayOfWeek + { + get + { + return this.ClockDateTime.DayOfWeek; + } + } + + public int DayOfYear + { + get + { + return this.ClockDateTime.DayOfYear; + } + } + + public int Hour + { + get + { + return this.ClockDateTime.Hour; + } + } + + public System.DateTime LocalDateTime + { + get + { + return this.UtcDateTime.ToLocalTime(); + } + } + + public int Millisecond + { + get + { + return this.ClockDateTime.Millisecond; + } + } + + public int Minute + { + get + { + return this.ClockDateTime.Minute; + } + } + + public int Month + { + get + { + return this.ClockDateTime.Month; + } + } + + public static DateTimeOffset Now + { + get + { + return new DateTimeOffset(System.DateTime.Now); + } + } + + public TimeSpan Offset + { + get + { + return new TimeSpan(0, this._offsetMinutes, 0); + } + } + + public int Second + { + get + { + return this.ClockDateTime.Second; + } + } + + public long Ticks + { + get + { + return this.ClockDateTime.Ticks; + } + } + + public TimeSpan TimeOfDay + { + get + { + return this.ClockDateTime.TimeOfDay; + } + } + + public System.DateTime UtcDateTime + { + get + { + return System.DateTime.SpecifyKind(this._dateTime, DateTimeKind.Utc); + } + } + + public static DateTimeOffset UtcNow + { + get + { + return new DateTimeOffset(System.DateTime.UtcNow); + } + } + + public long UtcTicks + { + get + { + return this.UtcDateTime.Ticks; + } + } + + public int Year + { + get + { + return this.ClockDateTime.Year; + } + } + } +} +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JavaScriptConvert.cs b/Src/Newtonsoft.Json/JavaScriptConvert.cs index b97a5097..14a86631 100644 --- a/Src/Newtonsoft.Json/JavaScriptConvert.cs +++ b/Src/Newtonsoft.Json/JavaScriptConvert.cs @@ -101,7 +101,14 @@ namespace Newtonsoft.Json /// A Json string representation of the . public static string ToString(DateTime value) { - return ToStringInternal(new DateTimeOffset(value), value.Kind); + TimeSpan utcOffset; +#if PocketPC + utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(value); +#else + utcOffset = TimeZoneInfo.Local.GetUtcOffset(value); +#endif + + return ToStringInternal(value, utcOffset, value.Kind); } /// @@ -111,31 +118,30 @@ namespace Newtonsoft.Json /// A Json string representation of the . public static string ToString(DateTimeOffset value) { - return ToStringInternal(value, DateTimeKind.Local); + return ToStringInternal(value.UtcDateTime, value.Offset, DateTimeKind.Local); } - internal static string ToStringInternal(DateTimeOffset value, DateTimeKind kind) + internal static string ToStringInternal(DateTime value, TimeSpan offset, DateTimeKind kind) { long javaScriptTicks = ConvertDateTimeToJavaScriptTicks(value); - string offset; + string timezoneOffset; switch (kind) { case DateTimeKind.Local: case DateTimeKind.Unspecified: - TimeSpan utcOffset = value.Offset; - offset = utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture); + timezoneOffset = offset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + offset.Minutes.ToString("00;00", CultureInfo.InvariantCulture); break; default: - offset = string.Empty; + timezoneOffset = string.Empty; break; } - return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + offset + @")\/"""; + return @"""\/Date(" + javaScriptTicks.ToString(CultureInfo.InvariantCulture) + timezoneOffset + @")\/"""; } - internal static long ConvertDateTimeToJavaScriptTicks(DateTimeOffset dateTime) + internal static long ConvertDateTimeToJavaScriptTicks(DateTime dateTime) { - DateTimeOffset utcDateTime = dateTime.ToUniversalTime(); + DateTime utcDateTime = dateTime.ToUniversalTime(); //if (utcDateTime < MinimumJavaScriptDate) // utcDateTime = MinimumJavaScriptDate; diff --git a/Src/Newtonsoft.Json/JsonHandler.cs b/Src/Newtonsoft.Json/JsonHandler.cs deleted file mode 100644 index 557932f8..00000000 --- a/Src/Newtonsoft.Json/JsonHandler.cs +++ /dev/null @@ -1,90 +0,0 @@ -#region License -// Copyright (c) 2007 James Newton-King -// -// Permission is hereby granted, free of charge, to any person -// obtaining a copy of this software and associated documentation -// files (the "Software"), to deal in the Software without -// restriction, including without limitation the rights to use, -// copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following -// conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// OTHER DEALINGS IN THE SOFTWARE. -#endregion - -#if !SILVERLIGHT -using System; -using System.Web; -using System.Web.Caching; -using System.Xml; -using System.Text; -using System.Security.Principal; - -namespace Newtonsoft.Json -{ - public abstract class JsonHandler : HandlerBase, IHttpHandler - { - public event EventHandler Error; - - protected abstract void WriteResult(JsonWriter writer); - - public static void JsonResponse(HttpResponse response, Action writeAction) - { - response.ClearHeaders(); - response.ClearContent(); - - JsonWriter writer = new JsonWriter(response.Output); - - writeAction(writer); - - writer.Flush(); - } - - protected virtual void OnError(EventArgs e) - { - if (Error != null) - { - Error(this, e); - } - } - - void IHttpHandler.ProcessRequest(HttpContext context) - { - if (context == null) - throw new ArgumentNullException("context"); - - Context = context; - - try - { - JsonHandler.JsonResponse(context.Response, new Action(WriteResult)); - } - catch (Exception exception) - { - context.AddError(exception); - OnError(EventArgs.Empty); - if (context.Error != null) - { - throw new HttpUnhandledException("blah", exception); - } - } - } - - bool IHttpHandler.IsReusable - { - get { return false; } - } - } -} -#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 580fde2c..b2bbf1c5 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -625,7 +625,7 @@ namespace Newtonsoft.Json } } - newObject = Activator.CreateInstance(objectType, constructorParameters.Values.ToArray()); + newObject = ReflectionUtils.CreateInstance(objectType, constructorParameters.Values.ToArray()); return newObject; } @@ -804,7 +804,7 @@ namespace Newtonsoft.Json { Type objectType = value.GetType(); -#if !SILVERLIGHT +#if !SILVERLIGHT && !PocketPC TypeConverter converter = TypeDescriptor.GetConverter(objectType); // use the objectType's TypeConverter if it has one and can convert to a string diff --git a/Src/Newtonsoft.Json/Linq/JValue.cs b/Src/Newtonsoft.Json/Linq/JValue.cs index dd250d11..a97e7dce 100644 --- a/Src/Newtonsoft.Json/Linq/JValue.cs +++ b/Src/Newtonsoft.Json/Linq/JValue.cs @@ -199,7 +199,9 @@ namespace Newtonsoft.Json.Linq return JsonTokenType.Integer; else if (value is double || value is float || value is decimal) return JsonTokenType.Float; - else if (value is DateTime || value is DateTimeOffset) + else if (value is DateTime) + return JsonTokenType.Date; + else if (value is DateTimeOffset) return JsonTokenType.Date; else if (value is bool) return JsonTokenType.Boolean; diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj new file mode 100644 index 00000000..2707860a --- /dev/null +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Compact.csproj @@ -0,0 +1,133 @@ + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {256AA604-F61B-4B6D-8D51-C8E6AB11E435} + Library + Properties + Newtonsoft.Json.Compact + Newtonsoft.Json.Compact + {4D628B5B-2FBC-4AA6-8C16-197242AEB884};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + PocketPC + b2c48bd2-963d-4549-9169-1fa021dce484 + 5.2 + Newtonsoft.Json.Compact + v3.5 + Windows Mobile 6 Professional SDK + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE;$(PlatformFamilyName) + true + true + prompt + 512 + 4 + Off + + + pdbonly + true + bin\Release\ + TRACE;$(PlatformFamilyName) + true + true + prompt + 512 + 4 + Off + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj index 20ec5856..afc49159 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Silverlight.csproj @@ -78,9 +78,6 @@ JsonConverterCollection.cs - - JsonHandler.cs - JsonIgnoreAttribute.cs @@ -224,7 +221,6 @@ - diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 624989cb..7adbec43 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -25,13 +25,16 @@ using System.Security; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -#if !SILVERLIGHT +#if SILVERLIGHT +[assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")] +[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Silverlight")] +#elif PocketPC +[assembly: AssemblyTitle("Newtonsoft Json.NET Compact")] +[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Compact")] +#else [assembly: AssemblyTitle("Newtonsoft Json.NET")] [assembly: InternalsVisibleTo("Newtonsoft.Json.Tests")] [assembly: AllowPartiallyTrustedCallers] -#else -[assembly: AssemblyTitle("Newtonsoft Json.NET Silverlight")] -[assembly: InternalsVisibleTo("Newtonsoft.Json.Tests.Silverlight")] #endif @@ -62,4 +65,6 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("3.0.0.0")] -[assembly: AssemblyFileVersion("3.0.0.0")] \ No newline at end of file +#if !PocketPC +[assembly: AssemblyFileVersion("3.0.0.0")] +#endif \ No newline at end of file diff --git a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs index 85c8aaca..fe656db3 100644 --- a/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/CollectionUtils.cs @@ -523,7 +523,7 @@ namespace Newtonsoft.Json.Utilities if (listType.IsArray) list = ToArray(((List)list).ToArray(), ReflectionUtils.GetCollectionItemType(listType)); else if (ReflectionUtils.InheritsGenericClassDefinition(listType, typeof(ReadOnlyCollection<>))) - list = (IList)Activator.CreateInstance(listType, list); + list = (IList)ReflectionUtils.CreateInstance(listType, list); } return list; diff --git a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs index 426dabe7..5b432318 100644 --- a/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ConvertUtils.cs @@ -102,6 +102,7 @@ namespace Newtonsoft.Json.Utilities if (initialValue is string && targetType == typeof(Guid)) return new Guid((string)initialValue); +#if !PocketPC // see if source or target types have a TypeConverter that converts between the two TypeConverter toConverter = GetConverter(initialType); @@ -124,6 +125,7 @@ namespace Newtonsoft.Json.Utilities return fromConverter.ConvertFrom(initialValue); #endif } +#endif // handle DBNull and INullable if (initialValue == DBNull.Value) @@ -330,6 +332,7 @@ namespace Newtonsoft.Json.Utilities } #endif +#if !PocketPC private static TypeConverter GetConverter(Type t) { ValidationUtils.ArgumentNotNull(t, "t"); @@ -345,6 +348,7 @@ namespace Newtonsoft.Json.Utilities return (Activator.CreateInstance(Type.GetType(typeConverterAttribute.ConverterTypeName)) as TypeConverter); #endif } +#endif public static bool IsInteger(object value) { diff --git a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs index 33c11d50..cb4bf15b 100644 --- a/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/DateTimeUtils.cs @@ -11,7 +11,12 @@ namespace Newtonsoft.Json.Utilities { public static string GetLocalOffset(this DateTime d) { - TimeSpan utcOffset = TimeZoneInfo.Local.GetUtcOffset(d); + TimeSpan utcOffset; +#if PocketPC + utcOffset = TimeZone.CurrentTimeZone.GetUtcOffset(d); +#else + utcOffset = TimeZoneInfo.Local.GetUtcOffset(d); +#endif return utcOffset.Hours.ToString("+00;-00", CultureInfo.InvariantCulture) + ":" + utcOffset.Minutes.ToString("00;00", CultureInfo.InvariantCulture); } diff --git a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs index df33be03..71ae1706 100644 --- a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs @@ -35,51 +35,6 @@ namespace Newtonsoft.Json.Utilities } } - public static bool TryGetDescription(object value, out string description) - { - return TryAction(delegate { return GetDescription(value); }, out description); - } - - public static string GetDescription(object o) - { - ValidationUtils.ArgumentNotNull(o, "o"); - - ICustomAttributeProvider attributeProvider = o as ICustomAttributeProvider; - - // object passed in isn't an attribute provider - // if value is an enum value, get value field member, otherwise get values type - if (attributeProvider == null) - { - Type valueType = o.GetType(); - - if (valueType.IsEnum) - attributeProvider = valueType.GetField(o.ToString()); - else - attributeProvider = valueType; - } - - DescriptionAttribute descriptionAttribute = ReflectionUtils.GetAttribute(attributeProvider); - - if (descriptionAttribute != null) - return descriptionAttribute.Description; - else - throw new Exception("No DescriptionAttribute on '{0}'.".FormatWith(CultureInfo.InvariantCulture, o.GetType())); - } - - public static IList GetDescriptions(IList values) - { - ValidationUtils.ArgumentNotNull(values, "values"); - - string[] descriptions = new string[values.Count]; - - for (int i = 0; i < values.Count; i++) - { - descriptions[i] = GetDescription(values[i]); - } - - return descriptions; - } - public static string ToString(object value) { if (value == null) diff --git a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs index 452d6d75..a46377aa 100644 --- a/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs +++ b/Src/Newtonsoft.Json/Utilities/ReflectionUtils.cs @@ -381,21 +381,6 @@ namespace Newtonsoft.Json.Utilities return (property.GetIndexParameters().Length > 0); } - public static MemberInfo GetMember(Type type, string name, MemberTypes memberTypes) - { - return GetMember(type, name, memberTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance); - } - - public static MemberInfo GetMember(Type type, string name, MemberTypes memberTypes, BindingFlags bindingAttr) - { - ValidationUtils.ArgumentNotNull(type, "type"); - ValidationUtils.ArgumentNotNull(name, "name"); - - MemberInfo[] result = type.GetMember(name, memberTypes, bindingAttr); - - return CollectionUtils.GetSingleItem(result); - } - /// /// Gets the member's value on the object. /// @@ -565,29 +550,6 @@ namespace Newtonsoft.Json.Utilities return t.FullName + ", " + t.Assembly.GetName().Name; } - public static List FindMembers(Type targetType, MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, object filterCriteria) - { - ValidationUtils.ArgumentNotNull(targetType, "targetType"); - - List memberInfos = new List(targetType.FindMembers(memberType, bindingAttr, filter, filterCriteria)); - - // fix weirdness with FieldInfos only being returned for the current Type - // find base type fields and add them to result - if ((memberType & MemberTypes.Field) != 0 - && (bindingAttr & BindingFlags.NonPublic) != 0) - { - // modify flags to not search for public fields - BindingFlags nonPublicBindingAttr = bindingAttr ^ BindingFlags.Public; - - while ((targetType = targetType.BaseType) != null) - { - memberInfos.AddRange(targetType.FindMembers(MemberTypes.Field, nonPublicBindingAttr, filter, filterCriteria)); - } - } - - return memberInfos; - } - public static Type MakeGenericType(Type genericTypeDefinition, params Type[] innerTypes) { ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition"); @@ -604,7 +566,7 @@ namespace Newtonsoft.Json.Utilities public static object CreateGeneric(Type genericTypeDefinition, IList innerTypes, params object[] args) { - return CreateGeneric(genericTypeDefinition, innerTypes, (t, a) => Activator.CreateInstance(t, a.ToArray()), args); + return CreateGeneric(genericTypeDefinition, innerTypes, (t, a) => ReflectionUtils.CreateInstance(t, a.ToArray()), args); } public static object CreateGeneric(Type genericTypeDefinition, IList innerTypes, Func, object> instanceCreator, params object[] args) @@ -617,5 +579,58 @@ namespace Newtonsoft.Json.Utilities return instanceCreator(specificType, args); } + + static object CreateInstance(this Assembly a, string typeName, params object[] pars) + { + var t = a.GetType(typeName); + var c = t.GetConstructor(pars.Select(p => p.GetType()).ToArray()); + if (c == null) + return null; + return c.Invoke(pars); + } + + public static bool IsCompatibleValue(object value, Type type) + { + if (value == null && IsNullable(type)) + return true; + + if (type.IsAssignableFrom(value.GetType())) + return true; + + return false; + } + + public static object CreateInstance(Type type, params object[] args) + { + ValidationUtils.ArgumentNotNull(type, "type"); + +#if !PocketPC + return Activator.CreateInstance(type, args); +#else + ConstructorInfo[] constructors = type.GetConstructors(); + ConstructorInfo match = constructors.Where(c => + { + ParameterInfo[] parameters = c.GetParameters(); + if (parameters.Length != args.Length) + return false; + + for (int i = 0; i < parameters.Length; i++) + { + ParameterInfo parameter = parameters[i]; + object value = args[i]; + + if (!IsCompatibleValue(value, parameter.ParameterType)) + return false; + } + + return true; + }).FirstOrDefault(); + + if (match == null) + throw new Exception("Could not create '{0}' with given parameters.".FormatWith(CultureInfo.InvariantCulture, args)); + + return match.Invoke(args); +#endif + } } } \ No newline at end of file