Пример #1
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>();
            }
                       ));
        }
        /// <summary>Create a formatter that just add or remove a prefix to values</summary>
        public static ITupleFormatter <T> CreateAppender(ITuple prefix)
        {
            if (prefix == null)
            {
                throw new ArgumentNullException(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", nameof(tuple));
                }
                if (!STuple.StartsWith(tuple, prefix))
                {
                    throw new ArgumentException("Tuple does not start with the expected prefix", nameof(tuple));
                }
                return tuple.Last <T>();
            }
                       ));
        }
 public PrefixedTuple Append <T>(T value)
 {
     return(new PrefixedTuple(m_prefix, m_items.Append <T>(value)));
 }
 /// <summary>Returns the key of a specific field of an HashSet: (subspace, id, field, )</summary>
 /// <param name="id"></param>
 /// <param name="field"></param>
 /// <returns></returns>
 protected virtual Slice GetFieldKey(ITuple id, string field)
 {
     //REVIEW: should the id be encoded as a an embedded tuple or not?
     return(this.Subspace.Keys.Pack(id.Append(field)));
 }