コード例 #1
0
 public MidAttributeRef(
     SourceRange range,
     MidAttributeDecl decl,
     ILazyFactory lazyFactory)
     : base(range, new MidDummyType())
 {
     _type = lazyFactory.New(() => Decl.Type);
     _decl = Lazy.Value(decl);
 }
コード例 #2
0
ファイル: MidAttributeFetch.cs プロジェクト: kzyg/spark
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: ResConceptClassDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #5
0
ファイル: LazySpecs.cs プロジェクト: nielzzz1993/FakeItEasy
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
ファイル: ResPipelineDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #13
0
ファイル: ResMethodDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #14
0
ファイル: ResPipelineDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #15
0
ファイル: ResMemberDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #16
0
ファイル: ResPipelineDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #17
0
ファイル: ResMemberDecl.cs プロジェクト: kzyg/spark
        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);
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
ファイル: LazyDictionary.cs プロジェクト: akhurst/ricealumni
 public LazyDictionary(ILazyFactory <TKey, TValue> factory)
 {
     _factory = factory;
     _inner   = new Dictionary <TKey, Tuple <bool, TValue> >();
 }
コード例 #20
0
        /// <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);
            }
        }
コード例 #21
0
        /// <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);
            }
        }
コード例 #22
0
 /// <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
 }
コード例 #23
0
		/// <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);
            }
		}
コード例 #24
0
 /// <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
 }
コード例 #25
0
 public MidExpFactory(
     ILazyFactory lazyFactory)
 {
     _lazyFactory = lazyFactory;
 }
コード例 #26
0
ファイル: Builder.cs プロジェクト: kzyg/spark
 public static ILazy <T> New <T>(
     this ILazyFactory factory,
     Func <T> generator)
 {
     return(new Lazy <T>(factory, generator));
 }
コード例 #27
0
 public void Register(Type type, string memberName, ILazyFactory factory)
 {
 }
コード例 #28
0
        /// <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);
            }
        }
コード例 #29
0
ファイル: Builder.cs プロジェクト: kzyg/spark
 public NewBuilder(
     ILazyFactory lazy)
 {
     _lazy = lazy;
     _lazy.Add(this);
 }