Implicit operators and class hierarchies
<p>I have the following class hierarchy.</p>

<pre><code>public abstract class ResourceBase { }

public abstract class WebResourceBase : ResourceBase  {
  public ResourceBase LocalPath { get; set; }
  public ResourceBase FtpPath { get; set; }
}

public class JavaScript : WebResourceBase { }
</code></pre>

<p>What I would like to do is have a declaration like so.</p>

<pre><code>new JavaScript() {
  LocalPath = "/path/goes/here/1.js",
  FtpPath = "ftp://path/goes/here/1.js"
}
</code></pre>

<p>The obvious answer here would be to use implicit operators but the problem is that I want to assign a derived type to those properties which is the same as the declared type so <code>LocalPath</code> and <code>FtpPath</code> would be of type <code>JavaScript</code>.</p>

<p>I'd like my solution to be more flexible than what I have at the moment. This code just makes my skin crawl. Was hoping there was a way using reflection and I have tried looking for information using the <code>StackTrace</code> class but no luck. Any help would be appreciated. Thanks.</p>

<pre><code>public abstract class ResourceBase { 
  public static implicit operator ResourceBase(string path) {
            if (path.EndsWith(".js"))
                return new JavaScript(path);
            // etc...
  }
}
</code></pre>
