コード例 #1
0
        /// <summary>
        /// Executes the method <see cref="FluentApiFactory.AssemblyFrom(Type[], string, string, Type, bool?)"/>.
        /// Make sure that you have already called the method <see cref="ScanAssemblyFrom(Type)"/>.
        /// </summary>
        /// <param name="fileName">The physical file name under which the dynamic fluent API assembly will be saved.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">You must first call one of the Scan methods.</exception>
        public FluentApiFactoryConfig Build(string fileName = null)
        {
            CheckDisposed();
            try
            {
                if (_assemblyTypes == null)
                {
                    ThrowScanRequired();
                }

                _result   = FluentApiFactory.AssemblyFrom(_assemblyTypes, fileName: fileName);
                _executed = true;

                if (!_result.Succeeded)
                {
                    _onErrorHandler?.Invoke(_result.Error);
                }
            }
            catch (Exception ex)
            {
                if (_onErrorHandler == null)
                {
                    throw;
                }
                _onErrorHandler?.Invoke(ex);
            }

            return(this);
        }
コード例 #2
0
        /// <summary>
        /// Reset the last execution configuration except for error handlers, and factory configuration options.
        /// The <see cref="FluentApiFactory"/>'s internal dictionary of previously created types, such as interfaces,
        /// proxies, and fluent API types, are also discarded.
        /// </summary>
        /// <returns></returns>
        public FluentApiFactoryConfig Reset()
        {
            CheckDisposed();
            FluentApiFactory.Reset();

            _result        = null;
            _executed      = false;
            _assemblyTypes = null;

            return(this);
        }
コード例 #3
0
        /// <summary>
        /// Dispose all resources used by the current <see cref="FluentApiFactoryConfig"/>,
        /// including error handlers, and optionally the last execution result.
        /// </summary>
        /// <param name="all">true to also discard the last execution result; otherwise, false.</param>
        /// <returns></returns>
        public FluentApiFactoryConfig ReleaseResources(bool all = false)
        {
            CheckDisposed();
            if (_onErrorHandler != null)
            {
                FluentApiFactory.Error -= _onErrorHandler;
                _onErrorHandler         = null;
            }

            if (_onDeleteHandler != null)
            {
                FluentApiFactory.DeleteFileError -= _onDeleteHandler;
                _onDeleteHandler = null;
            }
            if (all)
            {
                Reset();
            }
            else
            {
                FluentApiFactory.Reset();
            }
            return(this);
        }