ServiceStack/ServiceStack.Text — pull request #166 by sashagit (2012-08-15 01:26:09+00:00)
Title: The ServiceStack.Text.SL5 project was unable to build

The ServiceStack.Text.SL5 project would not build without some minor changes.

Updated files:
src/ServiceStack.Text/AssemblyUtils.cs
src/ServiceStack.Text/ReflectionExtensions.cs
src/ServiceStack.Text/StringExtensions.cs

diff --git a/src/ServiceStack.Text/AssemblyUtils.cs b/src/ServiceStack.Text/AssemblyUtils.cs
index 9d2e6fb..5ed868c 100644
--- a/src/ServiceStack.Text/AssemblyUtils.cs
+++ b/src/ServiceStack.Text/AssemblyUtils.cs
@@ -106,8 +106,8 @@ private static Assembly LoadAssembly(string assemblyPath)
#else
private static Assembly LoadAssembly(string assemblyPath)
{
- var sri = Application.GetResourceStream(new Uri(assemblyPath, UriKind.Relative));
- var myPart = new AssemblyPart();
+ 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;
}
diff --git a/src/ServiceStack.Text/ReflectionExtensions.cs b/src/ServiceStack.Text/ReflectionExtensions.cs
index 724b5ff..6ffec25 100644
--- a/src/ServiceStack.Text/ReflectionExtensions.cs
+++ b/src/ServiceStack.Text/ReflectionExtensions.cs
@@ -315,7 +315,11 @@ namespace ServiceStack.Text
#elif WINDOWS_PHONE
return Expression.Lambda(Expression.New(type)).Compile();
#else
+#if SILVERLIGHT
+ var dm = new System.Reflection.Emit.DynamicMethod("MyCtor", type, Type.EmptyTypes);
+#else
var dm = new System.Reflection.Emit.DynamicMethod("MyCtor", type, Type.EmptyTypes, typeof(ReflectionExtensions).Module, true);
+#endif
var ilgen = dm.GetILGenerator();
ilgen.Emit(System.Reflection.Emit.OpCodes.Nop);
ilgen.Emit(System.Reflection.Emit.OpCodes.Newobj, emptyCtor);
diff --git a/src/ServiceStack.Text/StringExtensions.cs b/src/ServiceStack.Text/StringExtensions.cs
index 8233373..6e84afc 100644
--- a/src/ServiceStack.Text/StringExtensions.cs
+++ b/src/ServiceStack.Text/StringExtensions.cs
@@ -170,7 +170,12 @@ namespace ServiceStack.Text
bytes.Add((byte)c);
}
}
+#if SILVERLIGHT
+ byte[] byteArray = bytes.ToArray();
+ return Encoding.UTF8.GetString(byteArray, 0, byteArray.Length);
+#else
return Encoding.UTF8.GetString(bytes.ToArray());
+#endif
}

#if !XBOX