コード例 #1
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T">Type of the only tuple field.</typeparam>
        /// <param name="descriptor">Tuple descriptor.</param>
        /// <param name="value">Value of the only tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T>(TupleDescriptor descriptor, T value)
        {
            RegularTuple tuple = Create(descriptor);

            tuple.SetValue(0, value);
            return(tuple);
        }
コード例 #2
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T1">Type of the first tuple field.</typeparam>
        /// <typeparam name="T2">Type of the 2nd tuple field.</typeparam>
        /// <param name="descriptor">Tuple descriptor.</param>
        /// <param name="value1">Value of the first tuple field.</param>
        /// <param name="value2">Value of the 2nd tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T1, T2>(TupleDescriptor descriptor, T1 value1, T2 value2)
        {
            RegularTuple tuple = Create(descriptor);

            tuple.SetValue(0, value1);
            tuple.SetValue(1, value2);
            return(tuple);
        }
コード例 #3
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T">Type of the only tuple field.</typeparam>
        /// <param name="value">Value of the only tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T>(T value)
        {
            TupleDescriptor descriptor = TupleDescriptor.Create(new[] {
                typeof(T)
            });

            return(Create(descriptor, value));
        }
コード例 #4
0
 /// <summary>
 /// Creates new <see cref="Tuple"/> by its descriptor.
 /// </summary>
 /// <param name="descriptor">The descriptor.</param>
 /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
 public static RegularTuple Create(TupleDescriptor descriptor)
 {
     if (descriptor == null)
     {
         throw new ArgumentNullException("descriptor");
     }
     return(new PackedTuple(descriptor));
 }
コード例 #5
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T1">Type of the first tuple field.</typeparam>
        /// <typeparam name="T2">Type of the 2nd tuple field.</typeparam>
        /// <param name="value1">Value of the first tuple field.</param>
        /// <param name="value2">Value of the 2nd tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T1, T2>(T1 value1, T2 value2)
        {
            TupleDescriptor descriptor = TupleDescriptor.Create(new[] {
                typeof(T1),
                typeof(T2)
            });

            return(Create(descriptor, value1, value2));
        }
コード例 #6
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T1">Type of the first tuple field.</typeparam>
        /// <typeparam name="T2">Type of the 2nd tuple field.</typeparam>
        /// <typeparam name="T3">Type of the 3rd tuple field.</typeparam>
        /// <typeparam name="T4">Type of the 4th tuple field.</typeparam>
        /// <param name="descriptor">Tuple descriptor.</param>
        /// <param name="value1">Value of the first tuple field.</param>
        /// <param name="value2">Value of the 2nd tuple field.</param>
        /// <param name="value3">Value of the 3rd tuple field.</param>
        /// <param name="value4">Value of the 4th tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T1, T2, T3, T4>(TupleDescriptor descriptor, T1 value1, T2 value2, T3 value3, T4 value4)
        {
            RegularTuple tuple = Create(descriptor);

            tuple.SetValue(0, value1);
            tuple.SetValue(1, value2);
            tuple.SetValue(2, value3);
            tuple.SetValue(3, value4);
            return(tuple);
        }
コード例 #7
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T1">Type of the first tuple field.</typeparam>
        /// <typeparam name="T2">Type of the 2nd tuple field.</typeparam>
        /// <typeparam name="T3">Type of the 3rd tuple field.</typeparam>
        /// <typeparam name="T4">Type of the 4th tuple field.</typeparam>
        /// <param name="value1">Value of the first tuple field.</param>
        /// <param name="value2">Value of the 2nd tuple field.</param>
        /// <param name="value3">Value of the 3rd tuple field.</param>
        /// <param name="value4">Value of the 4th tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
        {
            TupleDescriptor descriptor = TupleDescriptor.Create(new[] {
                typeof(T1),
                typeof(T2),
                typeof(T3),
                typeof(T4)
            });

            return(Create(descriptor, value1, value2, value3, value4));
        }
コード例 #8
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field value(s).
        /// </summary>
        /// <typeparam name="T1">Type of the first tuple field.</typeparam>
        /// <typeparam name="T2">Type of the 2nd tuple field.</typeparam>
        /// <typeparam name="T3">Type of the 3rd tuple field.</typeparam>
        /// <typeparam name="T4">Type of the 4th tuple field.</typeparam>
        /// <typeparam name="T5">Type of the 5th tuple field.</typeparam>
        /// <typeparam name="T6">Type of the 6th tuple field.</typeparam>
        /// <param name="value1">Value of the first tuple field.</param>
        /// <param name="value2">Value of the 2nd tuple field.</param>
        /// <param name="value3">Value of the 3rd tuple field.</param>
        /// <param name="value4">Value of the 4th tuple field.</param>
        /// <param name="value5">Value of the 5th tuple field.</param>
        /// <param name="value6">Value of the 6th tuple field.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create <T1, T2, T3, T4, T5, T6>(T1 value1, T2 value2, T3 value3, T4 value4, T5 value5, T6 value6)
        {
            TupleDescriptor descriptor = TupleDescriptor.Create(new[] {
                typeof(T1),
                typeof(T2),
                typeof(T3),
                typeof(T4),
                typeof(T5),
                typeof(T6)
            });

            return(Create(descriptor, value1, value2, value3, value4, value5, value6));
        }
コード例 #9
0
        /// <summary>
        /// Returns a <see cref="Tuple"/> with specified <paramref name="descriptor"/>
        /// parsed from the <paramref name="source"/> string.
        /// </summary>
        /// <param name="descriptor">The descriptor of <see cref="Tuple"/> to parse.</param>
        /// <param name="source">The string to parse.</param>
        /// <returns>A <see cref="Tuple"/> parsed from the <paramref name="source"/> string.</returns>
        /// <exception cref="System.InvalidOperationException"><paramref name="source"/> string
        /// can't be parsed to a <see cref="Tuple"/> with specified <paramref name="descriptor"/>.</exception>
        public static Tuple Parse(this TupleDescriptor descriptor, string source)
        {
            ArgumentValidator.EnsureArgumentNotNull(descriptor, "descriptor");
            var target  = Tuple.Create(descriptor);
            var count   = target.Count;
            var sources = source.RevertibleSplit(Escape, Comma).ToArray();

            for (int i = 0; i < count; i++)
            {
                ParseHandler.Get(descriptor[i]).Execute(sources, target, i);
            }
            return(target);
        }
コード例 #10
0
        // Constructors

        /// <summary>
        /// Initializes new instance of this type.
        /// </summary>
        /// <param name="source">The tuple to create the fast read-only tuple from.</param>
        public FastReadOnlyTuple(Tuple source)
        {
            descriptor = source.Descriptor;
            int count = descriptor.Count;

            values = new object[count];
            states = new TupleFieldState[count];
            for (int i = 0; i < count; i++)
            {
                TupleFieldState state;
                values[i] = source.GetValue(i, out state);
                states[i] = state;
            }
        }
コード例 #11
0
        /// <summary>
        /// Cuts out <paramref name="segment"/> from <paramref name="tuple"/> <see cref="Tuple"/>.
        /// </summary>
        /// <param name="tuple">The <see cref="Tuple"/> to get segment from.</param>
        /// <param name="segment">The <see cref="Segment{T}"/> to cut off.</param>
        /// <returns></returns>
        public static Tuple GetSegment(this Tuple tuple, Segment <int> segment)
        {
            var map = new int[segment.Length];

            for (int i = 0; i < segment.Length; i++)
            {
                map[i] = segment.Offset + i;
            }

            var types      = new ArraySegment <Type>(tuple.Descriptor.FieldTypes, segment.Offset, segment.Length);
            var descriptor = TupleDescriptor.Create(types.AsEnumerable());
            var transform  = new MapTransform(false, descriptor, map);

            return(transform.Apply(TupleTransformType.TransformedTuple, tuple));
        }
コード例 #12
0
 /// <see cref="TupleFormatExtensions.Parse" copy="true" />
 public static Tuple Parse(TupleDescriptor descriptor, string source)
 {
     return(descriptor.Parse(source));
 }
コード例 #13
0
        /// <summary>
        /// Creates new <see cref="Tuple"/> by its field types.
        /// </summary>
        /// <param name="fieldTypes">Array of field types.</param>
        /// <returns>Newly created <see cref="RegularTuple"/> object.</returns>
        public static RegularTuple Create(params Type[] fieldTypes)
        {
            TupleDescriptor descriptor = TupleDescriptor.Create(fieldTypes);

            return(Create(descriptor));
        }