// <summary> // Creates an instance of the underlying type for this dictionary, which may either be an entity type (in which // case CreateObject on the context is used) or a non-entity type (in which case the empty constructor is used.) // In either case, app domain cached compiled delegates are used to do the creation. // </summary> private object CreateObject() { if (_isEntityValues) { return(_internalContext.CreateObject(_type)); } Func <object> nonEntityFactory; if (!_nonEntityFactories.TryGetValue(_type, out nonEntityFactory)) { var factoryExpression = Expression.New(_type.GetDeclaredConstructor()); nonEntityFactory = Expression.Lambda <Func <object> >(factoryExpression, null).Compile(); _nonEntityFactories.TryAdd(_type, nonEntityFactory); } return(nonEntityFactory()); }
/// <summary> /// Creates an instance of the underlying type for this dictionary, which may either be an entity type (in which /// case CreateObject on the context is used) or a non-entity type (in which case the empty constructor is used.) /// In either case, app domain cached compiled delegates are used to do the creation. /// </summary> private object CreateObject() { if (_isEntityValues) { return(_internalContext.CreateObject(_type)); } Func <object> nonEntityFactory; if (!_nonEntityFactories.TryGetValue(_type, out nonEntityFactory)) { var factoryExpression = Expression.New( _type.GetConstructor( BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null)); nonEntityFactory = Expression.Lambda <Func <object> >(factoryExpression, null).Compile(); _nonEntityFactories.TryAdd(_type, nonEntityFactory); } return(nonEntityFactory()); }