Permalink
Browse files

Refactor to support PCL

  • Loading branch information...
mythz committed Dec 22, 2013
1 parent 5f97fcb commit d69b1ac453556c4ea76bd3d2be8b2a32ca00d046
Showing with 2,865 additions and 2,079 deletions.
  1. +26 −0 src/ServiceStack.Text.sln
  2. +20 −139 src/ServiceStack.Text/AssemblyUtils.cs
  3. +17 −131 src/ServiceStack.Text/AutoMappingUtils.cs
  4. +1 −1 src/ServiceStack.Text/Build.Silverlight.cs
  5. +0 −3 src/ServiceStack.Text/CollectionExtensions.cs
  6. +16 −35 src/ServiceStack.Text/Common/DateTimeSerializer.cs
  7. +1 −6 src/ServiceStack.Text/Common/DeserializeArray.cs
  8. +3 −11 src/ServiceStack.Text/Common/DeserializeBuiltin.cs
  9. +0 −3 src/ServiceStack.Text/Common/DeserializeCollection.cs
  10. +4 −35 src/ServiceStack.Text/Common/DeserializeDictionary.cs
  11. +4 −31 src/ServiceStack.Text/Common/DeserializeSpecializedCollections.cs
  12. +5 −102 src/ServiceStack.Text/Common/DeserializeType.cs
  13. +2 −2 src/ServiceStack.Text/Common/JsReader.cs
  14. +3 −89 src/ServiceStack.Text/Common/JsWriter.cs
  15. +4 −10 src/ServiceStack.Text/Common/WriteType.cs
  16. +0 −3 src/ServiceStack.Text/CsvWriter.cs
  17. +1 −8 src/ServiceStack.Text/DateTimeExtensions.cs
  18. +5 −0 src/ServiceStack.Text/DynamicJson.cs
  19. +0 −133 src/ServiceStack.Text/DynamicProxy.cs
  20. +22 −15 src/ServiceStack.Text/Env.cs
  21. +4 −6 src/ServiceStack.Text/HashSet.cs
  22. +97 −103 src/ServiceStack.Text/HttpUtils.cs
  23. +5 −14 src/ServiceStack.Text/JsConfig.cs
  24. +5 −11 src/ServiceStack.Text/JsConfigScope.cs
  25. +1 −1 src/ServiceStack.Text/Json/JsonTypeSerializer.cs
  26. +2 −2 src/ServiceStack.Text/Json/JsonWriter.Generic.cs
  27. +3 −5 src/ServiceStack.Text/JsonObject.cs
  28. +27 −68 src/ServiceStack.Text/JsonSerializer.cs
  29. +2 −2 src/ServiceStack.Text/Jsv/JsvTypeSerializer.cs
  30. +2 −2 src/ServiceStack.Text/Jsv/JsvWriter.Generic.cs
  31. +7 −65 src/ServiceStack.Text/LicenseUtils.cs
  32. +0 −95 src/ServiceStack.Text/Marc/ObjectAccessor.cs
  33. +0 −310 src/ServiceStack.Text/Marc/TypeAccessor.cs
  34. +6 −18 src/ServiceStack.Text/PathUtils.cs
  35. +1,304 −0 src/ServiceStack.Text/PclExport.Net40.cs
  36. +49 −0 src/ServiceStack.Text/PclExport.Sl5.cs
  37. +51 −0 src/ServiceStack.Text/PclExport.WP.cs
  38. +128 −0 src/ServiceStack.Text/PclExport.WinRT.cs
  39. +27 −0 src/ServiceStack.Text/PclExport.Xbox.cs
  40. +359 −0 src/ServiceStack.Text/PclExport.cs
  41. +1 −1 src/ServiceStack.Text/QueryStringSerializer.cs
  42. +3 −3 src/ServiceStack.Text/Reflection/StaticAccessors.cs
  43. +208 −236 src/ServiceStack.Text/ReflectionExtensions.cs
  44. +1 −1 src/ServiceStack.Text/Rsa/BigInteger.cs
  45. +1 −1 src/ServiceStack.Text/Rsa/Providers.cs
  46. +1 −1 src/ServiceStack.Text/Rsa/RSACryptoServiceProvider.cs
  47. +1 −1 src/ServiceStack.Text/Rsa/Scrypt.cs
  48. +1 −1 src/ServiceStack.Text/Rsa/Utils.cs
  49. +6 −3 src/ServiceStack.Text/ServiceStack.Text.Android.csproj
  50. +6 −3 src/ServiceStack.Text/ServiceStack.Text.AndroidIndie.csproj
  51. +267 −0 src/ServiceStack.Text/ServiceStack.Text.PCL.csproj
  52. +8 −5 src/ServiceStack.Text/ServiceStack.Text.SL5.csproj
  53. +6 −3 src/ServiceStack.Text/ServiceStack.Text.Signed.csproj
  54. +6 −3 src/ServiceStack.Text/ServiceStack.Text.csproj
  55. +1 −1 src/ServiceStack.Text/StreamExtensions.cs
  56. +83 −212 src/ServiceStack.Text/StringExtensions.cs
  57. +13 −41 src/ServiceStack.Text/Tracer.cs
  58. +1 −1 src/ServiceStack.Text/TypeConfig.cs
  59. +4 −19 src/ServiceStack.Text/TypeSerializer.cs
  60. +13 −63 src/ServiceStack.Text/XmlSerializer.cs
  61. +1 −1 tests/ServiceStack.Text.Tests/AotTests.cs
  62. +2 −2 tests/ServiceStack.Text.Tests/BasicStringSerializerTests.cs
  63. +1 −1 tests/ServiceStack.Text.Tests/CustomStructTests.cs
  64. +1 −1 tests/ServiceStack.Text.Tests/DateTimeOffsetAndTimeSpanTests.cs
  65. +1 −1 tests/ServiceStack.Text.Tests/DictionaryTests.cs
  66. +3 −3 tests/ServiceStack.Text.Tests/JsonTests/BasicJsonTests.cs
  67. +1 −1 tests/ServiceStack.Text.Tests/JsonTests/JsonDateTimeTests.cs
  68. +3 −3 tests/ServiceStack.Text.Tests/JsonTests/PolymorphicListTests.cs
  69. +2 −2 tests/ServiceStack.Text.Tests/NullableTypesTests.cs
  70. +1 −1 tests/ServiceStack.Text.Tests/ReportedIssues.cs
  71. +1 −1 tests/ServiceStack.Text.Tests/StringConverterUtilsTests.cs
  72. +1 −1 tests/ServiceStack.Text.Tests/StringSerializerTests.cs
  73. +1 −1 tests/ServiceStack.Text.Tests/StringSerializerTranslationTests.cs
  74. +2 −2 tests/ServiceStack.Text.Tests/StructTests.cs
View
@@ -24,6 +24,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{EEDB29
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceStack.Text.PCL", "ServiceStack.Text\ServiceStack.Text.PCL.csproj", "{9C22FC96-80DD-4C68-9B13-A8A96D3339B3}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -97,6 +99,30 @@ Global
{9770BD40-AA3B-4785-B5E0-F4C470F9F14E}.Signed|x86.ActiveCfg = Signed|x86
{9770BD40-AA3B-4785-B5E0-F4C470F9F14E}.Signed|x86.Build.0 = Signed|x86
{9770BD40-AA3B-4785-B5E0-F4C470F9F14E}.Signed|Xbox 360.ActiveCfg = Signed|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|ARM.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Debug|Xbox 360.ActiveCfg = Debug|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|ARM.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|x64.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|x86.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Release|Xbox 360.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|Any CPU.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|Any CPU.Build.0 = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|ARM.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|Mixed Platforms.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|Mixed Platforms.Build.0 = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|x64.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|x86.ActiveCfg = Release|Any CPU
+ {9C22FC96-80DD-4C68-9B13-A8A96D3339B3}.Signed|Xbox 360.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -4,9 +4,6 @@
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
-#if SILVERLIGHT
-
-#endif
using System.Threading;
using ServiceStack.Common.Support;
@@ -18,8 +15,6 @@ namespace ServiceStack.Text
public static class AssemblyUtils
{
private const string FileUri = "file:///";
- private const string DllExt = "dll";
- private const string ExeExt = "dll";
private const char UriSeperator = '/';
private static Dictionary<string, Type> TypeCache = new Dictionary<string, Type>();
@@ -35,7 +30,7 @@ public static Type FindType(string typeName)
Type type = null;
if (TypeCache.TryGetValue(typeName, out type)) return type;
-#if !SILVERLIGHT
+#if !SL5
type = Type.GetType(typeName);
#endif
if (type == null)
@@ -60,30 +55,20 @@ public static Type FindType(string typeName)
}
#endif
-#if !XBOX
-
-
- /// <summary>
- /// The top-most interface of the given type, if any.
- /// </summary>
- public static Type MainInterface<T>()
+ /// <summary>
+ /// The top-most interface of the given type, if any.
+ /// </summary>
+ public static Type MainInterface<T>()
{
- var t = typeof(T);
-#if NETFX_CORE
- if (t.GetTypeInfo().BaseType == typeof(object)) {
- // on Windows, this can be just "t.GetInterfaces()" but Mono doesn't return in order.
- var interfaceType = t.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(i => !t.GetTypeInfo().ImplementedInterfaces.Any(i2 => i2.GetTypeInfo().ImplementedInterfaces.Contains(i)));
- if (interfaceType != null) return interfaceType;
- }
-#else
- if (t.BaseType == typeof(object)) {
- // on Windows, this can be just "t.GetInterfaces()" but Mono doesn't return in order.
- var interfaceType = t.GetInterfaces().FirstOrDefault(i => !t.GetInterfaces().Any(i2 => i2.GetInterfaces().Contains(i)));
- if (interfaceType != null) return interfaceType;
- }
-#endif
- return t; // not safe to use interface, as it might be a superclass's one.
- }
+ var t = typeof(T);
+ if (t.BaseType() == typeof(object))
+ {
+ // on Windows, this can be just "t.GetInterfaces()" but Mono doesn't return in order.
+ var interfaceType = t.Interfaces().FirstOrDefault(i => !t.Interfaces().Any(i2 => i2.Interfaces().Contains(i)));
+ if (interfaceType != null) return interfaceType;
+ }
+ return t; // not safe to use interface, as it might be a superclass's one.
+ }
/// <summary>
/// Find type if it exists
@@ -99,80 +84,12 @@ public static Type FindType(string typeName, string assemblyName)
return type;
}
-#if !NETFX_CORE
- var binPath = GetAssemblyBinPath(Assembly.GetExecutingAssembly());
- Assembly assembly = null;
- var assemblyDllPath = binPath + String.Format("{0}.{1}", assemblyName, DllExt);
- if (File.Exists(assemblyDllPath))
- {
- assembly = LoadAssembly(assemblyDllPath);
- }
- var assemblyExePath = binPath + String.Format("{0}.{1}", assemblyName, ExeExt);
- if (File.Exists(assemblyExePath))
- {
- assembly = LoadAssembly(assemblyExePath);
- }
- return assembly != null ? assembly.GetType(typeName) : null;
-#else
- return null;
-#endif
+ return PclExport.Instance.FindType(typeName, assemblyName);
}
-#endif
-#if NETFX_CORE
- private sealed class AppDomain
- {
- public static AppDomain CurrentDomain { get; private set; }
- public static Assembly[] cacheObj = null;
-
- static AppDomain()
- {
- CurrentDomain = new AppDomain();
- }
-
- public Assembly[] GetAssemblies()
- {
- return cacheObj ?? GetAssemblyListAsync().Result.ToArray();
- }
-
- private async System.Threading.Tasks.Task<IEnumerable<Assembly>> GetAssemblyListAsync()
- {
- var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
-
- List<Assembly> assemblies = new List<Assembly>();
- foreach (Windows.Storage.StorageFile file in await folder.GetFilesAsync())
- {
- if (file.FileType == ".dll" || file.FileType == ".exe")
- {
- try
- {
- var filename = file.Name.Substring(0, file.Name.Length - file.FileType.Length);
- AssemblyName name = new AssemblyName() { Name = filename };
- Assembly asm = Assembly.Load(name);
- assemblies.Add(asm);
- }
- catch (Exception)
- {
- // Invalid WinRT assembly!
- }
- }
- }
-
- cacheObj = assemblies.ToArray();
-
- return cacheObj;
- }
- }
-#endif
-
-#if !XBOX
public static Type FindTypeFromLoadedAssemblies(string typeName)
{
-#if SILVERLIGHT4
- var assemblies = ((dynamic) AppDomain.CurrentDomain).GetAssemblies() as Assembly[];
-#else
- var assemblies = AppDomain.CurrentDomain.GetAssemblies();
-#endif
+ var assemblies = PclExport.Instance.GetAllAssemblies();
foreach (var assembly in assemblies)
{
var type = assembly.GetType(typeName);
@@ -183,46 +100,15 @@ public static Type FindTypeFromLoadedAssemblies(string typeName)
}
return null;
}
-#endif
-#if !SILVERLIGHT
- private static Assembly LoadAssembly(string assemblyPath)
- {
- return Assembly.LoadFrom(assemblyPath);
- }
-#elif NETFX_CORE
- private static Assembly LoadAssembly(string assemblyPath)
+ public static Assembly LoadAssembly(string assemblyPath)
{
- return Assembly.Load(new AssemblyName(assemblyPath));
+ return PclExport.Instance.LoadAssembly(assemblyPath);
}
-#elif WINDOWS_PHONE
- private static Assembly LoadAssembly(string assemblyPath)
- {
- return Assembly.LoadFrom(assemblyPath);
- }
-#else
- private static Assembly LoadAssembly(string assemblyPath)
- {
- var sri = System.Windows.Application.GetResourceStream(new Uri(assemblyPath, UriKind.Relative));
- var myPart = new System.Windows.AssemblyPart();
- var assembly = myPart.Load(sri.Stream);
- return assembly;
- }
-#endif
-#if !XBOX
public static string GetAssemblyBinPath(Assembly assembly)
{
-#if WINDOWS_PHONE
- var codeBase = assembly.GetName().CodeBase;
-#elif NETFX_CORE
- var codeBase = assembly.GetName().FullName;
-#elif SILVERLIGHT
- var codeBase = assembly.FullName;
-#else
- var codeBase = assembly.CodeBase;
-#endif
-
+ var codeBase = PclExport.Instance.GetAssemblyCodeBase(assembly);
var binPathPos = codeBase.LastIndexOf(UriSeperator);
var assemblyPath = codeBase.Substring(0, binPathPos + 1);
if (assemblyPath.StartsWith(FileUri, StringComparison.OrdinalIgnoreCase))
@@ -231,13 +117,8 @@ public static string GetAssemblyBinPath(Assembly assembly)
}
return assemblyPath;
}
-#endif
-#if !SILVERLIGHT
- static readonly Regex versionRegEx = new Regex(", Version=[^\\]]+", RegexOptions.Compiled);
-#else
- static readonly Regex versionRegEx = new Regex(", Version=[^\\]]+");
-#endif
+ static readonly Regex versionRegEx = new Regex(", Version=[^\\]]+", PclExport.Instance.RegexOptions);
public static string ToTypeString(this Type type)
{
return versionRegEx.Replace(type.AssemblyQualifiedName, "");
Oops, something went wrong.

0 comments on commit d69b1ac

Please sign in to comment.