This project has moved. For the latest updates, please go here.


FluentPath cannot be inherited because Fluent implementation is not generic


Look at this example:
public class MyPath : Path {
   public MyPath MyProcess() {
      //Just do it...
      return this;

public void Main(){
    var p = new MyPath("c:\\temp");
    p.AllFiles().MyProcess(); //Cannot compile
C# extension can resolve very partially the problem but where you need inheritance, you are stucked.

I have attached an implementation proposal that works (unit test cannot be run on my machine, so i cannot be absolutely sure)

file attachments

Closed Sep 13, 2014 at 5:32 PM by BertrandLeRoy


BertrandLeRoy wrote Jul 1, 2013 at 6:26 AM

I added a test to verify that this in fact works well with the latest code.

** Closed by BertrandLeRoy 06/30/2013 10:26PM

PlasmaSoft wrote Jul 4, 2013 at 7:51 AM

This test partially tests the problem. Try this instead:
 private class DerivedPath : Path {
            public DerivedPath(string path) : base(path) {}

            public bool DoStuff() {
                return true;

        public void DerivedPathWorks() {
            var derivedPath = new DerivedPath("foo");

            Assert.IsTrue(derivedPath.Parent().DoStuff()); //Cannot compile
See the attached file to view my proposal.

BertrandLeRoy wrote Sep 12, 2014 at 4:41 AM

Sorry it took so long, but this is now fixed. That was a hell of a refactoring, and I'm not very satisfied with the solution, but that's done.

PlasmaSoft wrote Sep 12, 2014 at 3:42 PM

Why aren't you satisfied with this solution ? it looks ok to me ...

BertrandLeRoy wrote Sep 13, 2014 at 5:32 PM

BertrandLeRoy wrote Sep 17, 2014 at 12:49 AM

Based on the arguments presented in the post and in the comments, I think I'll revert this change and seal the class instead. Can you explain what the scenario was that was justifying using inheritance instead of extension methods?