Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 086ab4b

Browse files
committed
Merge branch 'master' of https://github.com/ServiceStack/ServiceStack.Text into netcore
2 parents 6e9dd98 + acecaa3 commit 086ab4b

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

build/copy.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ COPY ..\src\ServiceStack.Text\bin\Signed\ServiceStack.Text.* ..\..\ServiceStack.
1515
COPY ..\src\ServiceStack.Text.SL5\bin\%BUILD%\ServiceStack.Text.* ..\..\ServiceStack\lib\sl5
1616

1717
COPY ..\src\ServiceStack.Text\bin\Pcl\ServiceStack.Text.dll ..\..\ServiceStack\lib\pcl
18+
19+
COPY ..\src\ServiceStack.Text\bin\Debug\netstandard1.1\*.* ..\..\ServiceStack\lib\netcore

src/ServiceStack.Text/AssemblyUtils.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public static Type FindType(string typeName)
4545
do
4646
{
4747
snapshot = TypeCache;
48-
newCache = new Dictionary<string, Type>(TypeCache);
49-
newCache[typeName] = type;
48+
newCache = new Dictionary<string, Type>(TypeCache) { [typeName] = type };
5049

5150
} while (!ReferenceEquals(
5251
Interlocked.CompareExchange(ref TypeCache, newCache, snapshot), snapshot));

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,26 +1022,6 @@ public static StringCollection ToStringCollection(List<string> items)
10221022

10231023
public static class PclExportExt
10241024
{
1025-
public static string ToFormUrlEncoded(this NameValueCollection queryParams)
1026-
{
1027-
var sb = new System.Text.StringBuilder();
1028-
foreach (string key in queryParams)
1029-
{
1030-
var values = queryParams.GetValues(key);
1031-
if (values == null) continue;
1032-
1033-
foreach (var value in values)
1034-
{
1035-
if (sb.Length > 0)
1036-
sb.Append('&');
1037-
1038-
sb.AppendFormat("{0}={1}", key.UrlEncode(), value.UrlEncode());
1039-
}
1040-
}
1041-
1042-
return sb.ToString();
1043-
}
1044-
10451025
//HttpUtils
10461026
public static WebResponse PostFileToUrl(this string url,
10471027
FileInfo uploadFileInfo, string uploadFileMimeType,

src/ServiceStack.Text/Reflection/StaticAccessors.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
// Licensed under the same terms of ServiceStack.
1111
//
1212
using System;
13+
using System.Collections.Generic;
1314
using System.Reflection;
15+
using System.Threading;
1416
using ServiceStack.Text;
1517
#if !XBOX
1618
using System.Linq.Expressions;
@@ -20,6 +22,52 @@ namespace ServiceStack.Reflection
2022
//Also exists in ServiceStack.Common in ServiceStack.Reflection namespace
2123
public static class StaticAccessors
2224
{
25+
private static Dictionary<string, Func<object, object>> getterFnCache = new Dictionary<string, Func<object, object>>();
26+
27+
public static Func<object, object> GetFastGetter(this Type type, string propName)
28+
{
29+
var key = $"{type.Namespace}.{type.Name}::{propName}";
30+
Func<object, object> fn;
31+
if (getterFnCache.TryGetValue(key, out fn))
32+
return fn;
33+
34+
fn = GetValueGetter(type.GetPropertyInfo(propName));
35+
36+
Dictionary<string, Func<object, object>> snapshot, newCache;
37+
do
38+
{
39+
snapshot = getterFnCache;
40+
newCache = new Dictionary<string, Func<object, object>>(getterFnCache) { [key] = fn };
41+
42+
} while (!ReferenceEquals(
43+
Interlocked.CompareExchange(ref getterFnCache, newCache, snapshot), snapshot));
44+
45+
return fn;
46+
}
47+
48+
private static Dictionary<string, Action<object, object>> setterFnCache = new Dictionary<string, Action<object, object>>();
49+
50+
public static Action<object, object> GetFastSetter(this Type type, string propName)
51+
{
52+
var key = $"{type.Namespace}.{type.Name}::{propName}";
53+
Action<object, object> fn;
54+
if (setterFnCache.TryGetValue(key, out fn))
55+
return fn;
56+
57+
fn = GetValueSetter(type.GetPropertyInfo(propName));
58+
59+
Dictionary<string, Action<object, object>> snapshot, newCache;
60+
do
61+
{
62+
snapshot = setterFnCache;
63+
newCache = new Dictionary<string, Action<object, object>>(setterFnCache) { [key] = fn };
64+
65+
} while (!ReferenceEquals(
66+
Interlocked.CompareExchange(ref setterFnCache, newCache, snapshot), snapshot));
67+
68+
return fn;
69+
}
70+
2371
public static Func<object, object> GetValueGetter(this PropertyInfo propertyInfo)
2472
{
2573
return GetValueGetter(propertyInfo, propertyInfo.DeclaringType);

src/ServiceStack.Text/ReflectionExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,9 @@ public static Type[] GetGenericArguments(this Type type)
8282
return type.GetTypeInfo().GenericTypeArguments;
8383
}
8484

85-
public static TypeInfo GetTypeInfo(this Type type)
85+
internal static TypeInfo GetTypeInfo(this Type type)
8686
{
87-
IReflectableType reflectableType = (IReflectableType)type;
88-
return reflectableType.GetTypeInfo();
87+
return ((IReflectableType)type).GetTypeInfo();
8988
}
9089
#endif
9190

@@ -1761,6 +1760,15 @@ public static bool IsGenericType(this Type type)
17611760
#endif
17621761
}
17631762

1763+
public static bool ContainsGenericParameters(this Type type)
1764+
{
1765+
#if (NETFX_CORE || PCL || NETSTANDARD1_1)
1766+
return type.GetTypeInfo().ContainsGenericParameters;
1767+
#else
1768+
return type.ContainsGenericParameters;
1769+
#endif
1770+
}
1771+
17641772
#if (NETFX_CORE)
17651773
public static object GetDefaultValue(this Type type)
17661774
{

0 commit comments

Comments
 (0)