Skip to content
Browse files

Merge branch 'master' of github.com:jsonfx/jsonfx

  • Loading branch information...
2 parents e4dd866 + 766ed0d commit fe61ab2310b750ca5ca4ba1f4633d0c7753dd320 @mckamey mckamey committed Sep 10, 2012
View
8 Build.bat
@@ -2,6 +2,7 @@
PUSHD "%~dp0"
SET MSBuild=%SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
+SET MSBuild35=%SystemRoot%\Microsoft.NET\Framework\v3.5\MSBuild.exe
IF NOT EXIST "%MSBuild%" (
ECHO Installation of .NET Framework 4.0 is required to build this project, including .NET v2.0 and v3.5 releases
ECHO http://www.microsoft.com/downloads/details.aspx?FamilyID=0a391abd-25c1-4fc0-919f-b21f31ab88b7
@@ -34,6 +35,12 @@ ECHO.
FOR %%i IN (%FrameworkVer%) DO "%MSBuild%" src/JsonFx/JsonFx.csproj /target:rebuild /property:TargetFrameworkVersion=%%i;Configuration=%Configuration%
+REM .net 3.5 Compact Framework -----------------------------------------------------
+
+IF EXIST "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets" (
+ "%MSBuild35%" src/JsonFx/JsonFx.csproj /target:rebuild /property:TargetFrameworkIdentifier=netcf;Configuration=%Configuration%
+)
+
REM Silverlight -----------------------------------------------------
IF EXIST "%ProgramFiles%\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" (
@@ -81,6 +88,7 @@ ECHO Copying files for packages...
xcopy build\%Configuration%_v4.0\*.* "packages\lib\net40\" /Y
xcopy build\%Configuration%_v3.5\*.* "packages\lib\net35\" /Y
xcopy build\%Configuration%_v2.0\*.* "packages\lib\net20\" /Y
+xcopy build\%Configuration%_v3.5_netcf\*.* "packages\lib\netcf35\" /Y
xcopy build\%Configuration%_v3.5_Silverlight\*.* "packages\lib\sl35\" /Y
xcopy build\%Configuration%_v4.0_Silverlight\*.* "packages\lib\sl40\" /Y
xcopy build\%Configuration%_v4.0_WindowsPhone\*.* "packages\lib\sl40-wp\" /Y
View
2 src/JsonFx.Tests/AssertPatched.cs
@@ -38,6 +38,7 @@ THE SOFTWARE.
namespace JsonFx
{
+#if NET4
public class AssertPatchedTests
{
#region Constants
@@ -141,6 +142,7 @@ public void AssertPatched_EquivalentNotStrictDictionaries_Passes()
#endregion AssertPatched Tests
}
+#endif
/// <summary>
/// Patches xunit.Assert to allow less strict comparisons (doesn't enforce exact type)
View
11 src/JsonFx.Tests/IO/SequenceBufferTests.cs
@@ -37,6 +37,17 @@ THE SOFTWARE.
namespace JsonFx.IO
{
+
+#if !NET40
+ public static class SequenceBufferHelpers
+ {
+ public static void Clear(this StringBuilder sb)
+ {
+ sb.Length = 0;
+ }
+ }
+#endif
+
public class SequenceBufferTests
{
#region Constants
View
9 src/JsonFx.Tests/JsonFx.Tests.csproj
@@ -69,6 +69,7 @@
<Reference Include="System.XML" />
<Reference Include="xunit">
<HintPath>$(SolutionDir)\lib\xUnit.net\xunit.dll</HintPath>
+ <HintPath>..\..\lib\xUnit.net\xunit.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' And '$(TargetFrameworkVersion)' != 'v3.0' ">
@@ -87,11 +88,17 @@
<Compile Include="Bson\BsonFormatterTests.cs" />
<Compile Include="Bson\BsonConverterTests.cs" />
<Compile Include="CodeGen\DynamicMethodGeneratorTests.cs" />
+ </ItemGroup>
+ <ItemGroup Condition="'$(TargetFrameworkIdentifier)' != 'netcf'">
<Compile Include="Model\ModelAnalyzerTests.cs" />
<Compile Include="Model\ModelWalkerTests.cs" />
<Compile Include="Model\Filters\Iso8601DateFilterTests.cs" />
<Compile Include="Model\Filters\MSAjaxDateFilterTests.cs" />
<Compile Include="Model\ModelSubsequencerTests.cs" />
+ <Compile Include="Serialization\TypeCoercionUtilityTests.cs" />
+ <Compile Include="Linq\QueryEngineTests.cs" />
+ </ItemGroup>
+ <ItemGroup>
<Compile Include="Html\HtmlFormatterTests.cs" />
<Compile Include="Html\HtmlTokenizerTests.cs" />
<Compile Include="Html\HtmlOutTransformerTests.cs" />
@@ -107,11 +114,9 @@
<Compile Include="Json\JsonFormatterTests.cs" />
<Compile Include="Json\JsonTokenizerTests.cs" />
<Compile Include="Json\Resolvers\JsonResolverStrategyTests.cs" />
- <Compile Include="Linq\QueryEngineTests.cs" />
<Compile Include="Serialization\Resolvers\ConventionResolverStrategyTests.cs" />
<Compile Include="Serialization\Resolvers\CombinedResolverStrategyTests.cs" />
<Compile Include="Serialization\Resolvers\DataContractResolverStrategyTests.cs" />
- <Compile Include="Serialization\TypeCoercionUtilityTests.cs" />
<Compile Include="Xml\XmlConverterTests.cs" />
<Compile Include="Xml\XmlFormatterTests.cs" />
<Compile Include="Xml\XmlInTransformerTests.cs" />
View
16 src/JsonFx/CodeGen/DynamicMethodGenerator_NoEmit.cs
@@ -118,7 +118,13 @@ public static GetterDelegate GetPropertyGetter(PropertyInfo propertyInfo)
return delegate(object instance)
{
- return methodInfo.Invoke(instance, Type.EmptyTypes);
+ return methodInfo.Invoke(instance,
+#if NETCF
+ new Type[]{}
+#else
+ Type.EmptyTypes
+#endif
+ );
};
}
@@ -282,7 +288,13 @@ public static FactoryDelegate GetTypeFactory(Type type)
throw new ArgumentNullException("type");
}
- ConstructorInfo ctor = type.GetConstructor(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.FlattenHierarchy, null, Type.EmptyTypes, null);
+ ConstructorInfo ctor = type.GetConstructor(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.FlattenHierarchy, null,
+#if NETCF
+ new Type[]{},
+#else
+ Type.EmptyTypes,
+#endif
+ null);
if (ctor == null)
{
return null;
View
42 src/JsonFx/Json/JsonTokenizer.cs
@@ -526,13 +526,13 @@ private static Token<ModelTokenType> ScanNumber(ITextStream scanner)
if (!hasDecimal && !hasExponent && precision < 19)
{
// Integer value
- decimal number;
- if (!Decimal.TryParse(
- buffer,
- NumberStyles.Integer,
- NumberFormatInfo.InvariantInfo,
- out number))
- {
+ decimal number = 0;
+ try{
+ number = Decimal.Parse(
+ buffer,
+ NumberStyles.Integer,
+ NumberFormatInfo.InvariantInfo);
+ }catch(Exception){
throw new DeserializationException(JsonTokenizer.ErrorIllegalNumber, numPos, numLine, numCol);
}
@@ -555,12 +555,12 @@ private static Token<ModelTokenType> ScanNumber(ITextStream scanner)
{
// Floating Point value
double number;
- if (!Double.TryParse(
- buffer,
- NumberStyles.Float,
- NumberFormatInfo.InvariantInfo,
- out number))
- {
+ try{
+ number = Double.Parse(
+ buffer,
+ NumberStyles.Float,
+ NumberFormatInfo.InvariantInfo);
+ }catch(Exception){
throw new DeserializationException(JsonTokenizer.ErrorIllegalNumber, numPos, numLine, numCol);
}
@@ -698,13 +698,15 @@ private static string ScanString(ITextStream scanner)
}
// unicode ordinal
- int utf16;
- if (escapeSeq.Length == UnicodeEscapeLength &&
- Int32.TryParse(
- escapeSeq,
- NumberStyles.AllowHexSpecifier,
- NumberFormatInfo.InvariantInfo,
- out utf16))
+ int utf16 = 0;
+ bool parsed = true;
+ try{
+ utf16 = Int32.Parse(
+ escapeSeq,
+ NumberStyles.AllowHexSpecifier,
+ NumberFormatInfo.InvariantInfo);
+ }catch(Exception){ parsed = false; };
+ if (escapeSeq.Length == UnicodeEscapeLength && parsed)
{
buffer.Append(CharUtility.ConvertFromUtf32(utf16));
}
View
21 src/JsonFx/JsonFx.csproj
@@ -9,6 +9,11 @@
<ProjectGuid>{3082284B-B579-4808-A4A4-D88DDA4025CB}</ProjectGuid>
<ProjectTypeGuids Condition=" '$(TargetFrameworkIdentifier)' == 'Silverlight' ">{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<ProjectTypeGuids Condition=" '$(TargetFrameworkProfile)' == 'WindowsPhone' ">{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+
+ <PlatformID Condition=" '$(TargetFrameworkIdentifier)' == 'netcf' ">b2c48bd2-963d-4549-9169-1fa021dce484</PlatformID>
+ <PlatformFamilyName Condition=" '$(TargetFrameworkIdentifier)' == 'netcf' ">PocketPC</PlatformFamilyName>
+ <TargetFrameworkVersion Condition=" '$(TargetFrameworkIdentifier)' == 'netcf' ">v3.5</TargetFrameworkVersion>
+
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JsonFx</RootNamespace>
@@ -68,9 +73,12 @@
<PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v4.0' ">
<DefineConstants>$(DefineConstants);NET40</DefineConstants>
</PropertyGroup>
- <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' ">
+ <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' and '$(TargetFrameworkIdentifier)' != 'netcf' ">
<DefineConstants>$(DefineConstants);NET35</DefineConstants>
</PropertyGroup>
+ <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' and '$(TargetFrameworkIdentifier)' == 'netcf' ">
+ <DefineConstants>$(DefineConstants);NETCF;NET30;SILVERLIGHT</DefineConstants>
+ </PropertyGroup>
<PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v2.0' Or '$(TargetFrameworkVersion)' == 'v3.0' ">
<DefineConstants>$(DefineConstants);NET20</DefineConstants>
<TargetFrameworkProfile>
@@ -89,7 +97,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
- <Reference Include="System.XML" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' And '$(TargetFrameworkVersion)' != 'v3.0' ">
<Reference Include="System.Core" />
@@ -201,13 +209,13 @@
<ItemGroup Condition=" '$(TargetFrameworkVersion)' == 'v2.0' Or '$(TargetFrameworkVersion)' == 'v3.0' ">
<Compile Include="Linq\ExtensionAttribute.cs" />
</ItemGroup>
- <ItemGroup Condition=" '$(TargetFrameworkProfile)' == 'WindowsPhone' ">
+ <ItemGroup Condition=" '$(TargetFrameworkProfile)' == 'WindowsPhone' or '$(TargetFrameworkIdentifier)' == 'netcf' ">
<Compile Include="CodeGen\DynamicMethodGenerator_NoEmit.cs" />
</ItemGroup>
- <ItemGroup Condition=" '$(TargetFrameworkProfile)' != 'WindowsPhone' ">
+ <ItemGroup Condition=" '$(TargetFrameworkProfile)' != 'WindowsPhone' and '$(TargetFrameworkIdentifier)' != 'netcf' ">
<Compile Include="CodeGen\DynamicMethodGenerator.cs" />
</ItemGroup>
- <ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' And '$(TargetFrameworkVersion)' != 'v3.0' And '$(TargetFrameworkProfile)' != 'WindowsPhone' ">
+ <ItemGroup Condition=" '$(TargetFrameworkVersion)' != 'v2.0' And '$(TargetFrameworkVersion)' != 'v3.0' And '$(TargetFrameworkProfile)' != 'WindowsPhone' and '$(TargetFrameworkIdentifier)' != 'netcf' ">
<Compile Include="Model\ModelReader_Query.cs" />
<Compile Include="Model\Query`1.cs" />
<Compile Include="Linq\BaseQueryProvider.cs" />
@@ -220,7 +228,8 @@
<Compile Include="Linq\Query`1.cs" />
</ItemGroup>
<ItemGroup />
- <Import Condition=" '$(TargetFrameworkIdentifier)' != 'Silverlight' " Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Condition=" '$(TargetFrameworkIdentifier)' != 'Silverlight' and '$(TargetFrameworkIdentifier)' != 'netcf' " Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+ <Import Condition=" '$(TargetFrameworkIdentifier)' == 'netcf' " Project="$(MSBuildBinPath)\Microsoft.CompactFramework.CSharp.targets" />
<Import Condition=" '$(TargetFrameworkIdentifier)' == 'Silverlight' And '$(TargetFrameworkProfile)' != 'WindowsPhone' And '$(TargetFrameworkVersion)' == 'v3.5' " Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" />
<Import Condition=" '$(TargetFrameworkIdentifier)' == 'Silverlight' And '$(TargetFrameworkProfile)' != 'WindowsPhone' And '$(TargetFrameworkVersion)' != 'v3.5' " Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(TargetFrameworkVersion)\Microsoft.Silverlight.CSharp.targets" />
<Import Condition=" '$(TargetFrameworkProfile)' == 'WindowsPhone' " Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
View
9 src/JsonFx/Model/Filters/Iso8601DateFilter.cs
@@ -178,13 +178,14 @@ public override bool TryWrite(DataWriterSettings settings, DateTime value, out I
/// <returns>true if parsing was successful</returns>
private static bool TryParseIso8601(string date, out DateTime value)
{
- if (!DateTime.TryParseExact(
+ try{
+ value = DateTime.ParseExact(
date,
Iso8601DateFilter.FullFormat,
CultureInfo.InvariantCulture,
- DateTimeStyles.RoundtripKind|DateTimeStyles.AllowWhiteSpaces|DateTimeStyles.NoCurrentDateDefault,
- out value))
- {
+ DateTimeStyles.RoundtripKind|DateTimeStyles.AllowWhiteSpaces|DateTimeStyles.NoCurrentDateDefault
+ );
+ }catch(Exception){
value = default(DateTime);
return false;
}
View
6 src/JsonFx/Serialization/DataName.cs
@@ -257,7 +257,11 @@ private static string GetTypeName(Type type)
}
}
- if (typeof(IDictionary).IsAssignableFrom(type) || type.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false) != null)
+ if (typeof(IDictionary).IsAssignableFrom(type)
+#if !NETCF
+ || type.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false) != null
+#endif
+ )
{
// generic IDictionary or IDictionary<,>
return "object";
View
24 src/JsonFx/Serialization/Resolvers/ResolverCache.cs
@@ -237,7 +237,10 @@ public FactoryMap(Type type)
Type argType = paramList[0].ParameterType;
if ((argType == typeof(string)) ||
- ((argType.GetInterface(TypeCoercionUtility.TypeGenericIEnumerable, false) == null) &&
+ (
+#if !NETCF
+ (argType.GetInterface(TypeCoercionUtility.TypeGenericIEnumerable, false) == null) &&
+#endif
(typeof(IEnumerable).IsAssignableFrom(argType))))
{
continue;
@@ -268,7 +271,10 @@ public FactoryMap(Type type)
// many collection types have an Add method
// which adds items one at a time
- Type collectionType = type.GetInterface(TypeCoercionUtility.TypeGenericICollection, false);
+ Type collectionType = null;
+#if !NETCF
+ collectionType = type.GetInterface(TypeCoercionUtility.TypeGenericICollection, false);
+#endif
if (collectionType != null)
{
methodInfo = collectionType.GetMethod("Add");
@@ -302,7 +308,11 @@ public IEnumerable<Type> ArgTypes
{
if (this.CollectionCtors == null)
{
+#if NETCF
+ return new Type[]{ };
+#else
return Type.EmptyTypes;
+#endif
}
return this.CollectionCtors.Keys;
@@ -348,7 +358,15 @@ internal static bool IsImmutableType(Type type)
return
!type.IsInterface &&
!type.IsAbstract &&
- (type.IsValueType || (type.GetConstructor(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.FlattenHierarchy, null, Type.EmptyTypes, null) == null));
+ (type.IsValueType ||
+ (type.GetConstructor(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.FlattenHierarchy,
+ null,
+#if NETCF
+ new Type[]{ },
+#else
+ Type.EmptyTypes,
+#endif
+ null) == null));
}
#endregion Utility Methods
View
41 src/JsonFx/Serialization/TypeCoercionUtility.cs
@@ -252,7 +252,11 @@ internal void SetMemberValue(object target, Type targetType, MemberMap memberMap
((System.Dynamic.DynamicObject)target).TrySetMember(new DynamicSetter(memberName), memberValue);
}
#endif
- else if (targetType != null && targetType.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false) != null)
+ else if (targetType != null
+#if !NETCF
+ && targetType.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false) != null
+#endif
+ )
{
throw new TypeCoercionException(String.Format(
TypeCoercionUtility.ErrorGenericIDictionary,
@@ -368,18 +372,17 @@ public object CoerceType(Type targetType, object value)
if (targetType == typeof(DateTime))
{
DateTime date;
- if (DateTime.TryParse(
+ try{
+ date = DateTime.Parse(
(string)value,
CultureInfo.InvariantCulture,
- DateTimeStyles.RoundtripKind|DateTimeStyles.AllowWhiteSpaces|DateTimeStyles.NoCurrentDateDefault,
- out date))
- {
+ DateTimeStyles.RoundtripKind|DateTimeStyles.AllowWhiteSpaces|DateTimeStyles.NoCurrentDateDefault);
if (date.Kind == DateTimeKind.Local)
{
return date.ToUniversalTime();
}
return date;
- }
+ }catch(Exception){}
if (JsonFx.Model.Filters.MSAjaxDateFilter.TryParseMSAjaxDate(
(string)value,
@@ -415,16 +418,12 @@ public object CoerceType(Type targetType, object value)
}
else if (targetType == typeof(TimeSpan))
{
- long ticks;
- if (Int64.TryParse((string)value, out ticks))
- {
- return TimeSpan.FromTicks(ticks);
- }
- TimeSpan timespan;
- if (TimeSpan.TryParse((string)value, out timespan))
- {
- return timespan;
- }
+ try{
+ return TimeSpan.FromTicks(Int64.Parse((string)value));
+ }catch(Exception){}
+ try{
+ return TimeSpan.Parse((string)value);
+ }catch(Exception){}
}
}
else if (targetType == typeof(TimeSpan))
@@ -781,7 +780,10 @@ internal static Type GetDictionaryItemType(Type targetType)
return null;
}
- Type dictionaryType = targetType.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false);
+ Type dictionaryType = null;
+#if !NETCF
+ dictionaryType = targetType.GetInterface(TypeCoercionUtility.TypeGenericIDictionary, false);
+#endif
if (dictionaryType == null)
{
// not an IDictionary<TKey, TVal>
@@ -821,7 +823,10 @@ internal static Type GetElementType(Type targetType)
return targetType.GetElementType();
}
- Type arrayType = targetType.GetInterface(TypeCoercionUtility.TypeGenericIEnumerable, false);
+ Type arrayType = null;
+#if !NETCF
+ arrayType = targetType.GetInterface(TypeCoercionUtility.TypeGenericIEnumerable, false);
+#endif
if (arrayType == null)
{
// not an IEnumerable<T>

0 comments on commit fe61ab2

Please sign in to comment.
Something went wrong with that request. Please try again.