Somedays Writing Code is Enough

Back to Listing

Somedays Writing Code is Enough


19 Aug, 2011


I wrote this today, it made me happy. Somedays, simply writing some code that you are proud of makes it all worth it.

public void ImportLiabilityCategoryInput(string[] categories)  
{
    ImportCategory(categories, InputDataGroupName.Liability);
}

public void ImportAssetCategoryInput(string[] categories)  
{
    ImportCategory(categories, InputDataGroupName.AssetExisting);      
}

private void ImportCategory(string[] categories, InputDataGroupName group)  
{

    WithASourceAndDestination(
        (source, destination) =>
        {
            foreach(var category in categories)
            {
                var inputData = source.ReadInputData(group, category);
                destination.WriteInputData(group, category, inputData);
             }
        });
}

private void WithASourceAndDestination(Action<IFileAccess, IFileAccess> action)  
{
    using(var source = SourceFile.OpenForReading(_FromModelFile))
    using(var destination = DestFile.OpenForReadWrite(_ToModelFile))
    {
        action(source, destination);
        destination.Defragment();
    }
}
Share this story

Bobby Johnson

About Author

I am a passionate engineer with an interest in shipping quality software, building strong collaborative teams and continuous improvement of my skills, team and the product.

comments powered by Disqus
Back to top