/// <summary> /// Applies the transformation. /// </summary> /// <param name="transformType">The type of transformation to perform.</param> /// <param name="source1">First transformation source.</param> /// <param name="source2">Second transformation source.</param> /// <returns>Transformation result - /// either <see cref="TransformedTuple"/> or <see cref="Tuple"/> descendant, /// dependently on specified <paramref name="transformType"/>.</returns> protected Tuple Apply(TupleTransformType transformType, Tuple source1, Tuple source2) { if (sourceCount > 2) { throw new InvalidOperationException(string.Format(Strings.ExTheNumberOfSourcesIsTooSmallExpected, sourceCount)); } switch (transformType) { case TupleTransformType.Auto: if (source1 is TransformedTuple) { goto case TupleTransformType.Tuple; } if (source2 is TransformedTuple) { goto case TupleTransformType.Tuple; } goto case TupleTransformType.TransformedTuple; case TupleTransformType.TransformedTuple: return(new MapTransformTuple3(this, source1, source2)); case TupleTransformType.Tuple: FixedList3 <Tuple> sources = new FixedList3 <Tuple>(source1, source2); Tuple result = Tuple.Create(Descriptor); sources.CopyTo(result, map); return(result); default: throw new ArgumentOutOfRangeException("transformType"); } }
/// <summary> /// Converts <paramref name="source"/> tuple to read-only one. /// </summary> /// <param name="source">The tuple to convert to read-only.</param> /// <param name="transformType">The type of transformation to perform.</param> /// <returns>Read-only version of <paramref name="source"/> tuple.</returns> public static Tuple ToReadOnly(this Tuple source, TupleTransformType transformType) { if (source == null) { return(null); } return(ReadOnlyTransform.Instance.Apply(transformType, source)); }
/// <inheritdoc/> public override Tuple Apply(TupleTransformType transformType, params object[] arguments) { ArgumentValidator.EnsureArgumentNotNull(arguments, "arguments"); switch (sourceCount) { case 1: return(Apply(transformType, (Tuple)arguments[0])); case 2: return(Apply(transformType, (Tuple)arguments[0], (Tuple)arguments[1])); case 3: return(Apply(transformType, (Tuple)arguments[0], (Tuple)arguments[1], (Tuple)arguments[2])); default: return(Apply(transformType, arguments.Cast <object, Tuple>())); } }
/// <summary> /// Applies the transformation. /// </summary> /// <param name="transformType">The type of transformation to perform.</param> /// <param name="sources">Transformation sources.</param> /// <returns>Transformation result - /// either <see cref="TransformedTuple"/> or <see cref="Tuple"/> descendant, /// dependently on specified <paramref name="transformType"/>.</returns> public Tuple Apply(TupleTransformType transformType, params Tuple[] sources) { ArgumentValidator.EnsureArgumentNotNull(sources, "sources"); if (sourceCount > sources.Length) { throw new InvalidOperationException(string.Format(Strings.ExTheNumberOfSourcesIsTooSmallExpected, sourceCount)); } switch (sourceCount) { case 1: return(Apply(transformType, sources[0])); case 2: return(Apply(transformType, sources[0], sources[1])); case 3: return(Apply(transformType, sources[0], sources[1], sources[2])); default: switch (transformType) { case TupleTransformType.Auto: foreach (Tuple tuple in sources) { if (tuple is TransformedTuple) { goto case TupleTransformType.Tuple; } } goto case TupleTransformType.TransformedTuple; case TupleTransformType.TransformedTuple: return(new MapTransformTuple(this, sources)); case TupleTransformType.Tuple: Tuple result = Tuple.Create(Descriptor); sources.CopyTo(result, map); return(result); default: throw new ArgumentOutOfRangeException("transformType"); } } }
/// <summary> /// Typed version of <see cref="Apply(TupleTransformType,object[])"/>. /// </summary> /// <param name="transformType">The type of transformation to perform.</param> /// <param name="source">Transformation argument.</param> /// <returns>Transformation result - /// either <see cref="TransformedTuple"/> or <see cref="Tuple"/> descendant, /// dependently on specified <paramref name="transformType"/>.</returns> public Tuple Apply(TupleTransformType transformType, Tuple source) { switch (transformType) { case TupleTransformType.Auto: // TODO: Implement "Auto" for generated read-only tuples, when they'll be ready case TupleTransformType.TransformedTuple: if (source is ReadOnlyTransformTuple) { return(source); } return(new ReadOnlyTransformTuple(source)); case TupleTransformType.Tuple: // TODO: Return generated read-only tuple copy return(new ReadOnlyTransformTuple(source.ToRegular())); default: throw new ArgumentOutOfRangeException("transformType"); } }
/// <see cref="MapTransform.Apply(TupleTransformType,Tuple,Tuple,Tuple)" copy="true" /> public new Tuple Apply(TupleTransformType transformType, Tuple source1, Tuple source2, Tuple source3) { return(base.Apply(transformType, source1, source2, source3)); }
/// <inheritdoc/> public override Tuple Apply(TupleTransformType transformType, params object[] arguments) { ArgumentValidator.EnsureArgumentNotNull(arguments, "arguments"); return(Apply(transformType, arguments[0])); }
/// <inheritdoc/> public abstract Tuple Apply(TupleTransformType transformType, params object[] arguments);
/// <see cref="MapTransform.Apply(TupleTransformType,Tuple)" copy="true" /> public Tuple Apply(TupleTransformType transformType, Tuple source1, T source2) { return(Apply(transformType, source1, Tuple.Create(source2))); }