How to support multiple custom types?
<p>I have a Types project where I define custom class objects that I want to work on in my main application.  The objects are basically derived from strings and parsed into a structure.  </p>

<p>I have two problems</p>

<p>1 - In a separate project I have a File reader class where I scan text files for the string types I have defined.  For  example by regular expression.  Currently I added my Types project as a project reference and I just list the regular expressions at the top of my read class. When i find a type I convert the string to the appropriate type. However how can i improve this so that is it directly connected to my Types project - so when i update it with new types the Read class knows that it should support the new types?</p>

<p>2 - I'm trying to create a DLL that works on these specific types after they are read from the text file.  How do I tell my DLL that I want to support the types in my Types project?  Do I have to make an overloaded function for each type I want to work on? Do I use an interface?</p>

<p>Any advice is greatly appreciated.</p>

<p><strong>EDIT</strong>: Added example code of what I''m trying to do</p>

<p>//PROJECT 1 - handles IO operation like Reading and writing<br>
//function in read class job is to find one of several predefined string types by regular expression...once found they are converted to the data structure (by passing string to constructor of type class defined in the other project</p>

<pre><code> public class Read
{
    public string[] FileList { get; set; }

    private static Int64 endOffset = 0;
    private FileStream readStream;
    private StreamReader sr;

    private System.Text.RegularExpressions.Regex type1 = new System.Text.RegularExpressions.Regex(@"@123:test");
    private System.Text.RegularExpressions.Regex type2 = new System.Text.RegularExpressions.Regex(@"TESTTYPE2");

    public Read(string[] fl)
    {
        FileList = fl;
    }

    public object ReturnMessage(FileStream readStream, out int x)
    {
        //readStream = new FileStream(file, FileMode.Open, FileAccess.Read);
        x = 0;
        //endOffset = 0;
        bool found = false;
        char ch;
        string line = string.Empty;

        object message = null;

        while (!(x &lt; 0)) //do this while not end of line (x = -1)
        {
            readStream.Position = endOffset;

            //line reader
            while (found == false)  //keep reading characters until end of line found
            {
                x = readStream.ReadByte();
                if (x &lt; 0)
                {
                    found = true;
                    break;
                }
                // else if ((x == 10) || (x == 13))
                if ((x == 10) || (x == 13))
                {
                    ch = System.Convert.ToChar(x);
                    line = line + ch;
                    x = readStream.ReadByte();
                    if ((x == 10) || (x == 13))
                    {
                        ch = System.Convert.ToChar(x);
                        line = line + ch;
                        found = true;
                    }
                    else
                    {
                        if (x != 10 &amp;&amp; (x != 13))
                        {
                            readStream.Position--;
                        }
                        found = true;
                    }
                }
                else
                {
                    ch = System.Convert.ToChar(x);
                    line = line + ch;
                }
            }//while - end line reader 



            //examine line (is it one of the supported types?)
            if (type1.IsMatch(line))
            {
                message = line;
                endOffset = readStream.Position;

                break;
            }
            else
            {
                endOffset = readStream.Position;
                found = false;
                line = string.Empty;
            }

        }//while not end of line


        return message;
    }

}
</code></pre>

<p>//PROJECT 2 - contains classes that define the types</p>

<p>//TYPE1 </p>

<pre><code>namespace MessageTypes.Type1
{
public sealed class Type1
{
    public List&lt;Part&gt; S2 { get; set; }

    public Type1(string s)
    {
        S2 = new List&lt;Part&gt;();
        string[] parts = s.Split(':');
        for (int i = 0; i &lt; parts.Length; i++)
        {
            S2.Add(new Part(parts[i]));
        }
    }
}

public sealed class Part
{
    public string P { get; set; }

    public Part(string s)
    {
        P = s;
    }
}
}
</code></pre>

<p>//TYPE 2</p>

<pre><code>namespace MessageTypes.Type2
{
public sealed class FullString
{
    public string FS { get; set; }

    public FullString(string s)
    {
        FS = s;
    }
}
}
</code></pre>

<p>//PROJECT 3</p>

<pre><code>class DoSomethingToTypeObject{

//detect type and call appropriate function to process

} 
</code></pre>

<p>//PROJECT 4 -- MAIN PROJECT with GUI </p>

<pre><code>    public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, RoutedEventArgs e)
    {
        if (tabControl1.SelectedIndex == 0) //Processing Mode 1
        {
            //load file list from main window - Mode1 tab
            IOHandler.Read read = new IOHandler.Read(new string[2] { @"C:\file1.txt", @"C:\file2.txt" });

            //read files
            foreach (string file in read.FileList)
            {

                //while not end of stream
                myobject = read.ProcessFile(file);

                DoSomethingtoTypeObject DS = new DoSomethingtoTypeObject(myobject);

                //write transoformed object
                write(myobject);
            }
        }
    }
}
</code></pre>
