Permalink
Browse files

re-factor JsConfig.ModelFactory code a bit

  • Loading branch information...
1 parent 5d7953f commit fe608e163d6c90844c89932d1768c20dcd72dc97 @mythz mythz committed Oct 2, 2012
@@ -18,7 +18,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
-using System.Runtime.Serialization;
using ServiceStack.Text.Json;
namespace ServiceStack.Text.Common
@@ -36,18 +35,10 @@ public static ParseStringDelegate GetParseMethod(TypeConfig typeConfig)
var map = DeserializeTypeRef.GetTypeAccessorMap(typeConfig, Serializer);
- EmptyCtorDelegate ctorFn = null;
- var provider = JsConfig.ConstructorProvider;
- if (provider != null) {
- ctorFn = provider(type);
- }
- if (ctorFn == null) {
- ctorFn = ReflectionExtensions.GetConstructorMethodToCache(type);
- }
- if (map == null) {
+ var ctorFn = JsConfig.ModelFactory(type);
+ if (map == null)
return value => ctorFn();
- }
-
+
return typeof(TSerializer) == typeof(Json.JsonTypeSerializer)
? (ParseStringDelegate)(value => DeserializeTypeRefJson.StringToType(type, value, ctorFn, map))
: value => DeserializeTypeRefJsv.StringToType(type, value, ctorFn, map);
@@ -327,7 +327,8 @@ internal static bool TreatAsRefType(Type valueType)
public static void Reset()
{
- tsTryToParsePrimitiveTypeValues = sTryToParsePrimitiveTypeValues = null;
+ ModelFactory = ReflectionExtensions.GetConstructorMethodToCache;
+ tsTryToParsePrimitiveTypeValues = sTryToParsePrimitiveTypeValues = null;
tsConvertObjectTypesIntoStringDictionary = sConvertObjectTypesIntoStringDictionary = null;
tsIncludeNullValues = sIncludeNullValues = null;
tsExcludeTypeInfo = sExcludeTypeInfo = null;
@@ -450,8 +451,8 @@ static void RegisterCsvSerializer()
/// This is helpful for integration with IoC containers where you need to call the container constructor.
/// Return null if you don't know how to construct the type and the parameterless constructor will be used.
/// </summary>
- public static Func<Type, EmptyCtorDelegate> ConstructorProvider { get; set; }
- }
+ public static EmptyCtorFactoryDelegate ModelFactory { get; set; }
+ }
#if MONOTOUCH
[MonoTouch.Foundation.Preserve(AllMembers=true)]
Oops, something went wrong.

0 comments on commit fe608e1

Please sign in to comment.