C# how to dynamically cast an object?
<p>I am building a helper object that has a property called Mailer. In reality Mailer can be either a System.Net.Mail.MailMessage or a Mono.System.Net.Mail.MailMessage. So I would preferably only want 1 declaration of mailer. </p>

<p>For example I don't want:</p>

<pre><code>private Mono.Mailing.MailMessage MonoMessage = new Mono.Mailing.MailMessage();
private System.Net.Mail.MailMessage MailMessage = new System.Net.Mail.MailMessage();
</code></pre>

<p>I would prefer </p>

<pre><code>object mailer;
</code></pre>

<p>Then in constructor</p>

<pre><code>switch (software)
            {
                case EnunInternalMailingSoftware.dotnet:
                    this.mailer = new System.Net.Mail.MailMessage();
                    break;
                case EnunInternalMailingSoftware.mono:
                    this.mailer = new Mono.Mailing.MailMessage(); 
                    break;
            }
</code></pre>

<p>The problem is that mailer has no properties at design time. So I can't compile my code. </p>

<p>How can this be fixed, am I taking the right approach. Thanks in advance</p>
