Ejemplo n.º 1
0
 /// <summary>
 /// DateTimeOffset 'FromSeed' strategy that returns DateTimeOffset(seed, offset).
 /// </summary>
 /// <param name="offset">The offset.</param>
 /// <returns>DateTimeOffset 'FromSeed' delegate.</returns>
 public static Func <long, DateTimeOffset> DateTimeOffsetFromSeed(TimeSpan offset)
 {
     return(delegate(long seed)
     {
         try
         {
             return new DateTimeOffset(seed, offset);
         }
         catch (ArgumentOutOfRangeException ex)
         {
             throw DataGenerationUtilities.FromSeedFailedException <DateTimeOffset>(seed, ex);
         }
     });
 }
Ejemplo n.º 2
0
        /// <summary>
        /// FromSeed strategy that converts seed to the targeted type using IConvertible.
        /// </summary>
        /// <typeparam name="TData">The targeted type.</typeparam>
        /// <returns>'FromSeed' delegate.</returns>
        /// <remarks>The <typeparamref name="TData"/> such that long can be converted to.</remarks>
        public static Func <long, TData> ConvertSeed <TData>()
        {
            Type clrType = typeof(TData);

            if (!supportedTypesForConvertSeed.Contains(typeof(TData)))
            {
                throw new TaupoNotSupportedException("This strategy is not supported for the type " + clrType.FullName + ". Try other strategies.");
            }

            return(delegate(long seed)
            {
                try
                {
                    var value = seed.ConvertToType <TData>();
                    return value;
                }
                catch (OverflowException ex)
                {
                    throw DataGenerationUtilities.FromSeedFailedException <TData>(seed, ex);
                }
            });
        }