Skip to content

Instantly share code, notes, and snippets.

@JefClaes
Created November 27, 2012 20:38
Show Gist options
  • Save JefClaes/4156855 to your computer and use it in GitHub Desktop.
Save JefClaes/4156855 to your computer and use it in GitHub Desktop.
Generic FlatFileReader draft
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestReader
{
class Program
{
static void Main(string[] args)
{
var reader = new GenericReader<Header, Data, Trailer> ();
var composite = reader.Read();
Console.WriteLine(composite.Data.SomeProperty);
Console.ReadLine();
}
}
public class GenericReader<THeader, TData, TTrailer>
where THeader : new()
where TData : new()
where TTrailer : new()
{
public GenericComposite<THeader, TData, TTrailer> Read()
{
var composite = new GenericComposite<THeader, TData, TTrailer>();
composite.Header = new THeader();
composite.Data = new TData();
composite.Trailer = new TTrailer();
return composite;
}
}
public class GenericComposite<THeader, TData, TTrailer>
{
public THeader Header { get; set; }
public TData Data { get; set; }
public TTrailer Trailer { get; set; }
}
public class Header {
public string SomeProperty { get { return "SomeProperty"; } }
}
public class Data {
public string SomeProperty { get { return "SomeProperty"; } }
}
public class Trailer {
public string SomeProperty { get { return "SomeProperty"; } }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment