1

I have an existing partial class that has extension methods applied to it, in one project.

I want to add an attribute to that class within a different project, but when I create a second partial class the extension methods disappear.

Initially I created the class with the new attribute as a child of the original class, but I want to avoid the tedious up-cast of an instance of the original class to the new child class (though this may be the "best" way in the end).

Is there anyway to add the attribute without losing the extension methods, without using inheritance?

Josh Russo
  • 3,080
  • 2
  • 41
  • 62

1 Answers1

3

You can't declare a partial class across projects - it's got to be in a single project.

Basically if you need an extra attribute on the class, you'll have to put that in the original project.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • 1
    @BalaR: Nope, there's no such restriction. So long as it's still a static top-level non-generic class, that's fine. In particular, in Edulinq I had one huge partial class spread across loads of files :) – Jon Skeet Sep 22 '11 at 20:48
  • Ah ok, I see. You are correct. It's not that the extension methods disappeared, it's that the class was redefined. Ok, so inheritance it is. – Josh Russo Sep 22 '11 at 20:50
  • @BalaR In fact you can add an extension method to any type indicator you can use in a method header, including interfaces. – Josh Russo Sep 22 '11 at 20:54