Skip to main content
RSS feed Subscribe to feed

 

Transformation: Simple Example

This data transformation example creates a custom transformation that returns every other row from the input and all columns.

First create a transformation:

internal class EveryOtherTransformation : CustomDataTransformation
{
    public EveryOtherTransformation() { }

    public EveryOtherTransformation(
			SerializationInfo info, StreamingContext context)
        : base(info, context) { }

    protected override void GetObjectData(
			SerializationInfo info, StreamingContext context)
    {
        base.GetObjectData(info, context);
    }

    protected override DataTransformationConnection ConnectCore(
			ImportContext importContext, DataRowReader input)
    {
         return DataTransformationConnection.CreateConnection(
                    delegate { 
						return new EveryOtherTransformationReader(input); 
					});
    }
}

A reader also needs to be created. It is this class that performs the actual work:

internal class EveryOtherTransformationReader : CustomDataRowReader
{
    private DataRowReader inputReader;

    public EveryOtherTransformationReader(DataRowReader inputReader)
    {
        this.inputReader = inputReader;
    }

    protected override IEnumerable<DataRowReaderColumn> GetColumnsCore()
    {
        return this.inputReader.Columns;
    }

    protected override ResultProperties GetResultPropertiesCore()
    {
        return this.inputReader.ResultProperties;
    }

    protected override void ResetCore()
    {
        this.inputReader.Reset();
    }

    protected override bool MoveNextCore()
    {
        return this.inputReader.MoveNext() && this.inputReader.MoveNext();
    }
}