diff --git a/VAR.Json/ObjectActivator.cs b/VAR.Json/ObjectActivator.cs index 69ed4f5..52d6588 100644 --- a/VAR.Json/ObjectActivator.cs +++ b/VAR.Json/ObjectActivator.cs @@ -6,7 +6,7 @@ namespace VAR.Json { public class ObjectActivator { - private static Dictionary> _creators = new Dictionary>(); + private static readonly Dictionary> _creators = new Dictionary>(); public static Func GetLambdaNew(Type type) { @@ -17,13 +17,18 @@ namespace VAR.Json lock (_creators) { + if (_creators.ContainsKey(type)) + { + return _creators[type]; + } + NewExpression newExp = Expression.New(type); LambdaExpression lambda = Expression.Lambda(typeof(Func), newExp); Func compiledLambdaNew = (Func)lambda.Compile(); _creators.Add(type, compiledLambdaNew); + return _creators[type]; } - return _creators[type]; } public static object CreateInstance(Type type)