Reputation: 3699
In my framework project I have a class that represents tabs in a content management system. In some framewrok implementations it is desirable to extend this class with defintions of tabs that are specific to that implementation. I had though to do this by changing the CmsTabs class to be partial, like this:
namespace Framework
{
/// <summary>
/// Class containing common CMS Tab names
/// </summary>
public static partial class CmsTab
{
/// <summary>
/// Information Tab
/// </summary>
public const string Information = "Information";
And then creating a class with the same name and namespace in the assembly that implements the framework.
However, when I build the framework assembly, the CmsTabs class appears no longer to be partial - it's members are hidden in the implementing assembly when I add the partial class to that. When disassembled in Reflector, I get this:
public class CmsTab
{...
Is there something I need to do to make it retain its partial status, assuming that it is possible to do what I am trying to do.
Thanks.
Upvotes: 7
Views: 4347
Reputation: 373
You can use Extension methods to add new methods to a class in other assembly.
Upvotes: 7
Reputation: 115538
You can't have a partial class span assemblies:
All partial-type definitions meant to be parts of the same type must be defined in the same assembly and the same module (.exe or .dll file). Partial definitions cannot span multiple modules.
Upvotes: 22
Reputation: 888177
Partial classes are a purely compile-time feature.
It is not possible to create a class definition that spans multiple assemblies.
Instead, you can make the class a non-static singleton, and allow implementations to inherit the class, add properties to it, and set the inherited version as the singleton instance.
If it's purely a collection of const
strings, you can make it a private partial
class, but add a link to the file in every project.
Upvotes: 6