Пример #1
0
        /// <summary>Test if the start of current tuple is equal to another tuple</summary>
        /// <param name="left">Larger tuple</param>
        /// <param name="right">Smaller tuple</param>
        /// <returns>True if the beginning of <paramref name="left"/> is equal to <paramref name="right"/> or if both tuples are identical</returns>
        public static bool StartsWith(this IVarTuple left, IVarTuple right)
        {
            Contract.NotNull(left, nameof(left));
            Contract.NotNull(right, nameof(right));

            //REVIEW: move this on ITuple interface ?
            return(TupleHelpers.StartsWith(left, right));
        }
Пример #2
0
        public static ITupleFormatter <T> CreateAppender([NotNull] ITuple prefix)
        {
            Contract.NotNull(prefix, nameof(prefix));

            return(new AnonymousTupleFormatter <T>(
                       (value) => prefix.Append <T>(value),
                       (tuple) =>
            {
                if (tuple.Count != prefix.Count + 1)
                {
                    throw new ArgumentException("Tuple size is invalid", "tuple");
                }
                if (!TupleHelpers.StartsWith(tuple, prefix))
                {
                    throw new ArgumentException("Tuple does not start with the expected prefix", "tuple");
                }
                return tuple.Last <T>();
            }
                       ));
        }