public MidAttributeRef( SourceRange range, MidAttributeDecl decl, ILazyFactory lazyFactory) : base(range, new MidDummyType()) { _type = lazyFactory.New(() => Decl.Type); _decl = Lazy.Value(decl); }
public MidAttributeFetch( SourceRange range, MidPath obj, MidAttributeDecl attribute, ILazyFactory lazyFactory) : base(range, new MidDummyType()) { _obj = obj; _type = lazyFactory.New(() => _attribute.Value.Type); _attribute = Lazy.Value(attribute); }
public MidAttributeFetch( SourceRange range, MidPath obj, MidAttributeDecl attribute, ILazyFactory lazyFactory ) : base(range, new MidDummyType()) { _obj = obj; _type = lazyFactory.New(() => _attribute.Value.Type); _attribute = Lazy.Value(attribute); }
public ResConceptClassDeclBuilder( ILazyFactory lazyFactory, ILazy <IResMemberLineDecl> line, SourceRange range, Identifier name) : base(lazyFactory) { var resConceptClassDecl = new ResConceptClassDecl( line, range, name, NewLazy(() => _thisParameter), NewLazy(() => (from mngb in _memberNameGroups.Values select mngb.Value).Eager())); SetValue(resConceptClassDecl); }
public static void LazyReturnValue( ILazyFactory fake, Lazy <IFoo> lazy) { "establish" .x(() => fake = A.Fake <ILazyFactory>()); "when calling a method that returns a lazy" .x(() => lazy = fake.Create()); "it should return a lazy" .x(() => lazy.Should().NotBeNull()); "it should return a lazy whose value is a dummy" .x(() => lazy.Value.Should().Be(FooFactory.Instance)); }
public static void LazyReturnValueOfDummyableType( ILazyFactory fake, Lazy <IFoo> lazy) { "Given a fake" .x(() => fake = A.Fake <ILazyFactory>()); "When calling an unconfigured method that returns a lazy of a dummyable type" .x(() => lazy = fake.Create()); "Then it should return a lazy" .x(() => lazy.Should().NotBeNull()); "And the value of the lazy should be a dummy" .x(() => lazy.Value.Should().Be(FooFactory.Instance)); }
public static void LazyReturnValueOfNonDummyableType( ILazyFactory fake, Lazy <Bar> lazy) { "Given a fake" .x(() => fake = A.Fake <ILazyFactory>()); "When calling a method that returns a lazy of a non-dummyable type" .x(() => lazy = fake.CreateBar()); "Then it should return a lazy" .x(() => lazy.Should().NotBeNull()); "And the value of the lazy should be null" .x(() => lazy.Value.Should().BeNull()); }
public ResFieldDeclBuilder( ILazyFactory lazyFactory, ILazy <IResMemberLineDecl> resLine, SourceRange range, Identifier name) : base(lazyFactory) { var resFieldDecl = new ResFieldDecl( resLine, range, name, NewLazy(() => _type), NewLazy(() => _init)); SetValue(resFieldDecl); }
public ResGenericDeclBuilder( ILazyFactory lazy, ILazy <IResMemberLineDecl> line, SourceRange range, Identifier name) : base(lazy) { var resGenericDecl = new ResGenericDecl( line, range, name, NewLazy(() => _parameters), NewLazy(() => _innerDecl)); SetValue(resGenericDecl); }
public ResAttributeDeclBuilder( ILazyFactory lazyFactory, ILazy <IResMemberLineDecl> line, SourceRange range, Identifier name) : base(lazyFactory) { var resAttributeDecl = new ResAttributeDecl( line, range, name, NewLazy(() => _type), NewLazy(() => _lazyInit == null ? null : _lazyInit.Value), NewLazy(() => _flags)); SetValue(resAttributeDecl); }
public static IResAttributeDecl Build( ILazyFactory lazyFactory, ILazy <IResMemberLineDecl> line, SourceRange range, Identifier name, Action <ResAttributeDeclBuilder> action) { var builder = new ResAttributeDeclBuilder( lazyFactory, line, range, name); builder.AddAction(() => action(builder)); builder.DoneBuilding(); return(builder.Value); }
public static IResPipelineDecl Build( ILazyFactory lazyFactory, ILazy <IResModuleDecl> module, SourceRange range, Identifier name, Action <ResPipelineDeclBuilder> action) { var builder = new ResPipelineDeclBuilder( lazyFactory, module, range, name); builder.AddAction(() => action(builder)); builder.DoneBuilding(); return(builder.Value); }
public ResMethodDeclBuilder( ILazyFactory lazyFactory, ILazy <IResMemberLineDecl> line, SourceRange range, Identifier name) : base(lazyFactory) { var resMethodDecl = new ResMethodDecl( line, range, name, NewLazy(() => _parameters), NewLazy(() => _resultType), NewLazy(() => _lazyBody == null ? null : _lazyBody.Value), NewLazy(() => _flavor)); SetValue(resMethodDecl); }
public ResFacetDeclBuilder( ILazyFactory lazyFactory, ResPipelineDeclBuilder parent, IResPipelineRef originalPipeline) : base(lazyFactory) { AddDependency(parent); DoneBuilding(NewBuilderPhase.Dependencies); _originalPipeline = originalPipeline; var resFacetDecl = new ResFacetDecl( Lazy.Value(originalPipeline), NewLazy(() => (from b in _directBaseFacets select b.Value).Eager()), NewLazy(() => (from mngb in _memberNameGroups.Values select mngb.Value).Eager())); SetValue(resFacetDecl); }
public ResMemberNameGroupBuilder( ILazyFactory lazyFactory, IResContainerFacetBuilder facet, Identifier name) : base(lazyFactory) { if (facet != null) { facet.AddAction(NewBuilderPhase.Seal, () => DoneBuilding()); AddDependency(facet); } DoneBuilding(NewBuilderPhase.Dependencies); _facet = facet; _name = name; var resMemberNameGroup = new ResMemberNameGroup( name, NewLazy(() => (from cgb in _categoryGroups.Values select cgb.Value).Eager())); SetValue(resMemberNameGroup); }
public ResPipelineDeclBuilder( ILazyFactory lazyFactory, ILazy <IResModuleDecl> module, SourceRange range, Identifier name) : base(lazyFactory) { _module = module; _range = range; _name = name; var resShaderClass = new ResPipelineDecl( _module, _range, _name, NewLazy(() => _thisParameter), NewLazy(() => _directFacet.Value), NewLazy(() => (from f in _facets select f.Value).Eager()), NewLazy(() => _mixinMode), NewLazy(() => _concretenessMode)); SetValue(resShaderClass); }
public ResMemberLineDeclBuilder( ResMemberCategoryGroupBuilder parent, ILazyFactory lazy, Identifier name, ResLexicalID originalLexicalID, ResMemberCategory category) : base(lazy) { parent.AddAction(NewBuilderPhase.Seal, () => DoneBuilding()); AddDependency(parent); DoneBuilding(NewBuilderPhase.Dependencies); var resMemberLineDecl = new ResMemberLineDecl( name, originalLexicalID, category, NewLazy(() => _concretenessMode), NewLazy(() => _declMode), NewLazy(() => _tags.ToArray()), NewLazy(() => _directDecl), NewLazy(() => _inheritedDecls.ToArray())); SetValue(resMemberLineDecl); }
public void Initialize(ConfigurationScope configScope, Type resultClass) { if (((this._propertyName.Length > 0) && (this._propertyName != "value")) && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!this._isComplexMemberName) { this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, this._propertyName); } else { MemberInfo memberInfoForSetter = ObjectProbe.GetMemberInfoForSetter(resultClass, this._propertyName); string name = this._propertyName.Substring(this._propertyName.LastIndexOf('.') + 1); this._setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(memberInfoForSetter.ReflectedType, name); } this._isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType); this._isIList = typeof(IList).IsAssignableFrom(this.MemberType); if (this._isGenericIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else { Type[] genericArguments = this.MemberType.GetGenericArguments(); if (genericArguments.Length == 0) { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } else { Type type2 = typeof(IList <>).MakeGenericType(genericArguments); Type type3 = typeof(List <>); Type type4 = type3.MakeGenericType(genericArguments); if ((type2 == this.MemberType) || (type4 == this.MemberType)) { Type typeToCreate = type3.MakeGenericType(genericArguments); this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(typeToCreate, Type.EmptyTypes); } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } else if (this._isIList) { if (this.MemberType.IsArray) { this._listFactory = _arrayListFactory; } else if (this.MemberType == typeof(IList)) { this._listFactory = _arrayListFactory; } else { this._listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } if ((this.CallBackName != null) && (this.CallBackName.Length > 0)) { configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' check the typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { ITypeHandlerCallback callback = (ITypeHandlerCallback)Activator.CreateInstance(configScope.SqlMapper.TypeHandlerFactory.GetType(this.CallBackName)); this._typeHandler = new CustomTypeHandler(callback); goto Label_0320; } catch (Exception exception) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + exception.Message, exception); } } configScope.ErrorContext.MoreInfo = "Result property '" + this._propertyName + "' set the typeHandler attribute."; this._typeHandler = configScope.ResolveTypeHandler(resultClass, this._propertyName, this._clrType, this._dbType, true); Label_0320: if (this.IsLazyLoad) { this._lazyFactory = new LazyFactoryBuilder().GetLazyFactory(this._setAccessor.MemberType); } }
public LazyDictionary(ILazyFactory <TKey, TValue> factory) { _factory = factory; _inner = new Dictionary <TKey, Tuple <bool, TValue> >(); }
/// <summary> /// Initializes a new instance of the <see cref="ResultProperty"/> class. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="columnName">Name of the column.</param> /// <param name="columnIndex">Index of the column.</param> /// <param name="clrType">Type of the CLR.</param> /// <param name="callBackName">Name of the call back.</param> /// <param name="dbType">Type of the db.</param> /// <param name="isLazyLoad">if set to <c>true</c> [is lazy load].</param> /// <param name="nestedResultMapName">Name of the nested result map.</param> /// <param name="nullValue">The null value.</param> /// <param name="select">The select.</param> /// <param name="resultClass">The result class.</param> /// <param name="dataExchangeFactory">The data exchange factory.</param> /// <param name="typeHandler">The type handler.</param> public ResultProperty( string propertyName, string columnName, int columnIndex, string clrType, string callBackName, string dbType, bool isLazyLoad, string nestedResultMapName, string nullValue, string select, Type resultClass, DataExchangeFactory dataExchangeFactory, ITypeHandler typeHandler ) { Contract.Require.That(propertyName, Is.Not.Null & Is.Not.Empty).When("retrieving argument propertyName in ResultProperty constructor"); this.propertyName = propertyName; this.columnName = columnName; this.callBackName = callBackName; this.dbType = dbType; this.clrType = clrType; this.select = select; this.nestedResultMapName = nestedResultMapName; this.isLazyLoad = isLazyLoad; this.nullValue = nullValue; this.columnIndex = columnIndex; this.typeHandler = typeHandler; #region isComplexMemberName if (propertyName.IndexOf('.') < 0) { isComplexMemberName = false; } else // complex member name FavouriteLineItem.Id { isComplexMemberName = true; } #endregion if (propertyName.Length > 0 && propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass) && !typeof(DataRow).IsAssignableFrom(resultClass)) { #region SetAccessor if (!isComplexMemberName) { setAccessor = dataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, propertyName); string memberName = propertyName.Substring(propertyName.LastIndexOf('.') + 1); setAccessor = dataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } #endregion isGenericIList = TypeUtils.IsImplementGenericIListInterface(MemberType); isIList = typeof(IList).IsAssignableFrom(MemberType); #region Set the list factory if (isGenericIList) { if (MemberType.IsArray) { listFactory = arrayListFactory; } else { Type[] typeArgs = MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList <>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List <>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == MemberType) || (listType == MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); listFactory = dataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } else if (isIList) { if (MemberType.IsArray) { listFactory = arrayListFactory; } else { if (MemberType == typeof(IList)) { listFactory = arrayListFactory; } else // custom collection { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } #endregion } #region TypeHandler if (!string.IsNullOrEmpty(CallBackName)) { try { Type type = dataExchangeFactory.TypeHandlerFactory.GetType(CallBackName); ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type); this.typeHandler = new CustomTypeHandler(typeHandlerCallback); } catch (Exception e) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e); } } else { if (typeHandler == null) { //configScope.ErrorContext.MoreInfo = "Result property '" + propertyName + "' set the typeHandler attribute."; this.typeHandler = dataExchangeFactory.TypeHandlerFactory.ResolveTypeHandler(resultClass, propertyName, clrType, dbType, true); } } #endregion #region LazyLoad if (IsLazyLoad) { lazyFactory = new LazyFactoryBuilder().GetLazyFactory(setAccessor.MemberType); } #endregion if (!GetType().IsSubclassOf(typeof(ResultProperty))) { propertyStrategy = PropertyStrategyFactory.Get(this); } }
/// <summary> /// Initializes a new instance of the <see cref="ResultProperty"/> class. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="columnName">Name of the column.</param> /// <param name="columnIndex">Index of the column.</param> /// <param name="clrType">Type of the CLR.</param> /// <param name="callBackName">Name of the call back.</param> /// <param name="dbType">Type of the db.</param> /// <param name="isLazyLoad">if set to <c>true</c> [is lazy load].</param> /// <param name="nestedResultMapName">Name of the nested result map.</param> /// <param name="nullValue">The null value.</param> /// <param name="select">The select.</param> /// <param name="resultClass">The result class.</param> /// <param name="dataExchangeFactory">The data exchange factory.</param> /// <param name="typeHandler">The type handler.</param> public ResultProperty( string propertyName, string columnName, int columnIndex, string clrType, string callBackName, string dbType, bool isLazyLoad, string nestedResultMapName, string nullValue, string select, Type resultClass, DataExchangeFactory dataExchangeFactory, ITypeHandler typeHandler ) { Contract.Require.That(propertyName, Is.Not.Null & Is.Not.Empty).When("retrieving argument propertyName in ResultProperty constructor"); this.propertyName = propertyName; this.columnName = columnName; this.callBackName = callBackName; this.dbType = dbType; this.clrType = clrType; this.select = select; this.nestedResultMapName = nestedResultMapName; this.isLazyLoad = isLazyLoad; this.nullValue = nullValue; this.columnIndex = columnIndex; this.typeHandler = typeHandler; #region isComplexMemberName if (propertyName.IndexOf('.') < 0) { isComplexMemberName = false; } else // complex member name FavouriteLineItem.Id { isComplexMemberName = true; } #endregion if ( propertyName.Length>0 && propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass)&& !typeof(DataRow).IsAssignableFrom(resultClass)) { #region SetAccessor if (!isComplexMemberName) { setAccessor = dataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, propertyName); string memberName = propertyName.Substring(propertyName.LastIndexOf('.') + 1); setAccessor = dataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } #endregion isGenericIList = TypeUtils.IsImplementGenericIListInterface(MemberType); isIList = typeof(IList).IsAssignableFrom(MemberType); #region Set the list factory if (isGenericIList) { if (MemberType.IsArray) { listFactory = arrayListFactory; } else { Type[] typeArgs = MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList<>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List<>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == MemberType) || (listType == MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); listFactory = dataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } else if (isIList) { if (MemberType.IsArray) { listFactory = arrayListFactory; } else { if (MemberType == typeof(IList)) { listFactory = arrayListFactory; } else // custom collection { listFactory = dataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } #endregion } #region TypeHandler if (!string.IsNullOrEmpty(CallBackName)) { try { Type type = dataExchangeFactory.TypeHandlerFactory.GetType(CallBackName); ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type); this.typeHandler = new CustomTypeHandler(typeHandlerCallback); } catch (Exception e) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e); } } else { if (typeHandler == null) { //configScope.ErrorContext.MoreInfo = "Result property '" + propertyName + "' set the typeHandler attribute."; this.typeHandler = dataExchangeFactory.TypeHandlerFactory.ResolveTypeHandler(resultClass, propertyName, clrType, dbType, true); } } #endregion #region LazyLoad if (IsLazyLoad) { lazyFactory = new LazyFactoryBuilder().GetLazyFactory(setAccessor.MemberType); } #endregion if (!GetType().IsSubclassOf(typeof(ResultProperty))) { propertyStrategy = PropertyStrategyFactory.Get(this); } }
/// <summary> /// Register (add) a lazy load Proxy for a type and member type /// </summary> /// <param name="type">The target type which contains the member proxyfied</param> /// <param name="memberName">The member name the proxy must emulate</param> /// <param name="factory">The <see cref="ILazyFactory"/>.</param> public void Register(Type type, string memberName, ILazyFactory factory) { // To use for further used, support for custom proxy }
/// <summary> /// Initialize the PropertyInfo of the result property. /// </summary> /// <param name="resultClass"></param> /// <param name="configScope"></param> public void Initialize( ConfigurationScope configScope, Type resultClass ) { if ( _propertyName.Length>0 && _propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass) ) { if (!_isComplexMemberName) { _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, _propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, _propertyName); string memberName = _propertyName.Substring( _propertyName.LastIndexOf('.')+1); _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } _isGenericIList = TypeUtils.IsImplementGenericIListInterface(this.MemberType); _isIList = typeof(IList).IsAssignableFrom(this.MemberType); // set the list factory if (_isGenericIList) { if (this.MemberType.IsArray) { _listFactory = _arrayListFactory; } else { Type[] typeArgs = this.MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList<>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List<>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == this.MemberType) || (listType == this.MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } else if (_isIList) { if (this.MemberType.IsArray) { _listFactory = _arrayListFactory; } else { if (this.MemberType == typeof(IList)) { _listFactory = _arrayListFactory; } else // custom collection { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(this.MemberType, Type.EmptyTypes); } } } } if (this.CallBackName!=null && this.CallBackName.Length >0) { configScope.ErrorContext.MoreInfo = "Result property '"+_propertyName+"' check the typeHandler attribute '" + this.CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { Type type = configScope.SqlMapper.TypeHandlerFactory.GetType(this.CallBackName); ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback) Activator.CreateInstance( type ); _typeHandler = new CustomTypeHandler(typeHandlerCallback); } catch (Exception e) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e); } } else { configScope.ErrorContext.MoreInfo = "Result property '"+_propertyName+"' set the typeHandler attribute."; _typeHandler = configScope.ResolveTypeHandler( resultClass, _propertyName, _clrType, _dbType, true); } if (this.IsLazyLoad) { _lazyFactory = new LazyFactoryBuilder().GetLazyFactory(_setAccessor.MemberType); } }
/// <summary> /// Register (add) a lazy load Proxy for a type and member type /// </summary> /// <param name="type">The target type which contains the member proxyfied</param> /// <param name="memberName">The member name the proxy must emulate</param> /// <param name="factory">The <see cref="ILazyFactory"/>.</param> public void Register(Type type, string memberName, ILazyFactory factory) { // To use for further used, support for custom proxy }
public MidExpFactory( ILazyFactory lazyFactory) { _lazyFactory = lazyFactory; }
public static ILazy <T> New <T>( this ILazyFactory factory, Func <T> generator) { return(new Lazy <T>(factory, generator)); }
public void Register(Type type, string memberName, ILazyFactory factory) { }
/// <summary> /// Initialize the PropertyInfo of the result property. /// </summary> /// <param name="resultClass"></param> /// <param name="configScope"></param> public void Initialize(ConfigurationScope configScope, Type resultClass) { if (_propertyName.Length > 0 && _propertyName != "value" && !typeof(IDictionary).IsAssignableFrom(resultClass)) { if (!_isComplexMemberName) { _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(resultClass, _propertyName); } else // complex member name FavouriteLineItem.Id { MemberInfo propertyInfo = ObjectProbe.GetMemberInfoForSetter(resultClass, _propertyName); string memberName = _propertyName.Substring(_propertyName.LastIndexOf('.') + 1); _setAccessor = configScope.DataExchangeFactory.AccessorFactory.SetAccessorFactory.CreateSetAccessor(propertyInfo.ReflectedType, memberName); } //#if dotnet2 _isGenericIList = TypeUtils.IsImplementGenericIListInterface(MemberType); //#endif _isIList = typeof(IList).IsAssignableFrom(MemberType); // set the list factory //#if dotnet2 if (_isGenericIList) { if (MemberType.IsArray) { _listFactory = _arrayListFactory; } else { Type[] typeArgs = MemberType.GetGenericArguments(); if (typeArgs.Length == 0)// Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } else { Type genericIList = typeof(IList <>); Type interfaceListType = genericIList.MakeGenericType(typeArgs); Type genericList = typeof(List <>); Type listType = genericList.MakeGenericType(typeArgs); if ((interfaceListType == MemberType) || (listType == MemberType)) { Type constructedType = genericList.MakeGenericType(typeArgs); _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory( constructedType, Type.EmptyTypes); } else // Custom collection which derive from List<T> { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } else //#endif if (_isIList) { if (MemberType.IsArray) { _listFactory = _arrayListFactory; } else { if (MemberType == typeof(IList)) { _listFactory = _arrayListFactory; } else // custom collection { _listFactory = configScope.DataExchangeFactory.ObjectFactory.CreateFactory(MemberType, Type.EmptyTypes); } } } } if (CallBackName != null && CallBackName.Length > 0) { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' check the typeHandler attribute '" + CallBackName + "' (must be a ITypeHandlerCallback implementation)."; try { Type type = configScope.SqlMapper.TypeHandlerFactory.GetType(CallBackName); ITypeHandlerCallback typeHandlerCallback = (ITypeHandlerCallback)Activator.CreateInstance(type); _typeHandler = new CustomTypeHandler(typeHandlerCallback); } catch (Exception e) { throw new ConfigurationException("Error occurred during custom type handler configuration. Cause: " + e.Message, e); } } else { configScope.ErrorContext.MoreInfo = "Result property '" + _propertyName + "' set the typeHandler attribute."; _typeHandler = configScope.ResolveTypeHandler(resultClass, _propertyName, _clrType, _dbType, true); } if (IsLazyLoad) { _lazyFactory = new LazyFactoryBuilder().GetLazyFactory(_setAccessor.MemberType); } }
public NewBuilder( ILazyFactory lazy) { _lazy = lazy; _lazy.Add(this); }