Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 326935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:21:19+00:00 2026-05-12T09:21:19+00:00

I have a maintenance application that has to turn enterprise data (from various databases/tables)

  • 0

I have a maintenance application that has to turn enterprise data (from various databases/tables) into flat files, each in a specific format, for consumption by a legacy application. I’ve got data models like

public class StatusCode
{
    public String Id { get; set; }
    public Char Level { get; set; }
    public String Description { get; set; }
}

I will select some subset or all of these records from the data source. And I need to map each entity to one line of the file, which may require adjusting the data (padding, transforming, or handling null).

public delegate String MapEntity<T>(T entity);
public MapEntity<StatusCode> MapStatusCode = delegate(StatusCode entity)
{
    return String.Format("{0},{1},{2}",
        entity.Id.PadLeft(3, '0'),
        entity.Level == 'S' ? 0 : 1,
        entity.Description ?? "-");
}

The question is, how do I write the transformation classes? Do I provide a “DefaultFileCreator” that takes a mapping delegate?

public interface IFileCreator
{
    Byte[] Create<T>(MapEntity<T> map, IEnumerable<T> entities);
}

public class DefaultFileCreator : IFileCreator
{
    public Byte[] Create<T>(MapEntity<T> map, IEnumerable<T> entities)
    {
        StringBuilder sb = new StringBuilder();
        foreach (T entity in entities)
            sb.AppendLine(map(entity));

        return Encoding.Default.GetBytes(sb.ToString());
    }
}

...
fileCreator.Create(MapStatusCode, repository<StatusCode>.FindAll());
...

With this solution, I’m concerned about where and in what scope I should keep the mapping delegates. And how I’m going to call them without knowing T (if I ever need to).

Or, do I change the interface and require the mapping in the concrete classes?

public interface IFileCreator<T>
{
    Byte[] Create(IEnumerable<T> entities);
}

public abstract class FileCreator : IFileCreator<T>
{
    protected abstract String Map(T entity);

    public Byte[] Create(IEnumerable<T> entities)
    {
        StringBuilder sb = new StringBuilder();
        foreach (T entity in entities)
            sb.AppendLine(Map(entity));

        return Encoding.Default.GetBytes(sb.ToString());
    }
}

public class StatusCodeFile : FileCreator<StatusCode>
{
    public override String Map(T entity)
    {
        return String.Format("{0},{1},{2}",
            entity.Id.PadLeft(3, '0'),
            entity.Level == 'S' ? 0 : 1,
            entity.Description ?? "-");
    }
}

This solution explodes in concrete classes, but they’re as thin as the mapping delegates. And I feel more comfortable working with IFileCreator<T> and a factory. (again, only if necessary).

I’m assuming some base class is useful as the StringBuilder loop and Byte[] encoding are straightforward. Should the concrete class set a delegate property in the base class (rather than calling an abstract method)? Should I keep the type parameter on the method (and how would that affect the base/concrete classes)?

I’m up for any solution. My main goal is ease of maintenance. I have 12 models/files right now and this may increase up to 21. I may have a requirement to insert arbitrary header/footer lines in any file (which is why I like the overrideable base class method, Map).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T09:21:19+00:00Added an answer on May 12, 2026 at 9:21 am

    Now that I’ve written a few of the transformations, I’m leaning towards the mapping-per-class approach,. I have to be able to run unit tests against faked models to ensure the files are built properly (testing them against known good sample files).

    I’ve been making the mapping-delegates private to the “workflow” class they belong in (one “workflow” per model/file). I’d have to make them public to unit test them, or output the intermediate file content (the workflow saves the completed files to a data store).

    The mapping-per-class seems a lot more testable and decomposable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mixed application that has data both in a database and in
I have a C# Application that does some maintenance tasks. It needs to run
I have an application that has several objects (about 50 so far, but growing).
In a current C# application I do maintenance on, we have upgraded to Visual
I am doing some maintenance on a VB6 Windows application. I have a .Net
We have an old project that requires occasional maintenance that uses VS2003 and Dot
I have an SSIS package that I've saved under Maintenance Plans on SQL Server
We have an enterpise web application that did consist of 4 compiled components (DLLs).
I have a project I am doing some maintenance work on and have got
Is there any performance hit from querying over two (or more) databases on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.