/// <summary>Sets transformation configuration that will be used for the transformation flow.</summary>
        /// <param name="configuration">Transformation configuration.</param>
        public TransformationBuilder<TSource, TDestination> WithConfiguration(TransformationConfiguration configuration)
        {
            ArgGuard.NotNull(configuration, nameof(configuration));

            Configuration = configuration;
            return this;
        }
        public void NotNull_PassedArgumentIsNull_ExceptionThrown()
        {
            var thrownException = Assert.Throws <ArgumentNullException>(() => ArgGuard.NotNull(null, "arg2"));

            Assert.IsNotNull(thrownException);
            Assert.AreEqual("arg2".GetArgumentNullExceptionMessage(), thrownException.Message);
        }
 /// <summary>Add the transformation step to the transformation chain.</summary>
 public TransformationBuilder<TSource, TDestination> Apply(AbstractTransformation<TSource, TDestination> transformation)
 {
     ArgGuard.NotNull(transformation, nameof(transformation));
    
     Transformations.Add(transformation);
     return this;
 }
        /// <summary>Executes the specified action on the transformation.</summary>
        /// <param name="action">An action to execute.</param>
        public TransformationBuilder<TSource, TDestination> Do(Func<TSource, TDestination, TransformationContext, TDestination> action)
        {
            ArgGuard.NotNull(action, nameof(action));

            Transformations.Add(new ActionTransformer<TSource, TDestination>(action));
            return this;
        }
        /// <summary>Add the specified isolated transformation step to the transformation chain if the specified condition returns true.</summary>
        /// <param name="condition">The condition function that defines whether to apply the specified transformation. It's evaluated in run-time when the
        /// transformation is going.</param>
        /// <param name="transformation">The transformation to apply.</param>
        public TransformationBuilder<TSource, TDestination> IfApplyIsolated(Func<TSource, TDestination, TransformationContext, bool> condition,
            AbstractTransformation<TSource, TDestination> transformation)
        {
            ArgGuard.NotNull(condition, nameof(condition));
            ArgGuard.NotNull(transformation, nameof(transformation));

            Transformations.Add(new ConditionalTransformer<TSource, TDestination>(condition, transformation.Transform, true));
            return this;
        }
 /// <summary>Add the isolated transformation step to the transformation chain.</summary>
 public TransformationBuilder<TSource, TDestination> ApplyIsolated(AbstractTransformation<TSource, TDestination> transformation, bool? keepInitialDestination = null)
 {
     ArgGuard.NotNull(transformation, nameof(transformation));
   
     transformation.IsIsolatedResult = true;
     transformation.KeepInitialDestination = keepInitialDestination ?? !Configuration.IsolateInitialDestination;
     Transformations.Add(transformation);
     return this;
 }
 /// <summary>Applies the transformation <paramref name="action"/> only when <paramref name="condition"/> returns true.</summary>
 /// <param name="condition">The condition to evaluate.</param>
 /// <param name="action">The action to execute when condition is true.</param>
 public TransformationBuilder<TSource, TDestination> IfDo(Func<TSource, TDestination, TransformationContext, bool> condition,
     Func<TSource, TDestination, TransformationContext, TDestination> action)
 {
     ArgGuard.NotNull(condition, nameof(condition));
     ArgGuard.NotNull(action, nameof(action));
   
     Transformations.Add(new ConditionalTransformer<TSource, TDestination>(condition, action));
     return this;
 }
Exemple #8
0
        public Paging(int itemCount, int pageSize, int?currentPage = null)
        {
            ArgGuard.MakeSure(itemCount >= 0, nameof(itemCount));
            ArgGuard.MakeSure(pageSize >= 1, nameof(pageSize));

            var(totalPages, actualCurrentPage) = NormalizePaging(itemCount, pageSize, currentPage);

            this.ItemCount   = itemCount;
            this.PageSize    = pageSize;
            this.TotalPages  = totalPages;
            this.CurrentPage = actualCurrentPage;
        }
        public SubStream(Stream baseStream, long offset, long length)
        {
            ArgGuard.ThrowIfNull(baseStream, nameof(baseStream));
            ArgGuard.ThrowIfFalse(baseStream.CanRead, nameof(baseStream));
            ArgGuard.ThrowIfFalse(baseStream.CanSeek, nameof(baseStream));
            ArgGuard.ThrowIfFalse(offset >= 0, nameof(offset));

            _baseStream = baseStream;
            _position   = 0;
            _offset     = offset;
            _length     = length;

            baseStream.Seek(offset, SeekOrigin.Current);
        }
        public void NotNull_PassedArgumentIsNotNull_NoExceptionThrown()
        {
            Exception thrownException = null;

            try
            {
                ArgGuard.NotNull("sdf", "arg1");
            }
            catch (Exception exc)
            {
                thrownException = exc;
            }

            Assert.IsNull(thrownException);
        }