Reputation: 83254
Does C# allows partial interface? i.e., in ManagerFactory1.cs class, I have
public partial interface IManagerFactory
{
// Get Methods
ITescoManager GetTescoManager();
ITescoManager GetTescoManager(INHibernateSession session);
}
and in ManagerFactory.cs class, I have:
public partial interface IManagerFactory
{
// Get Methods
IEmployeeManager GetEmployeeManager();
IEmployeeManager GetEmployeeManager(INHibernateSession session);
IProductManager GetProductManager();
IProductManager GetProductManager(INHibernateSession session);
IStoreManager GetStoreManager();
IStoreManager GetStoreManager(INHibernateSession session);
}
Both ManagerFactory and ManagerFactory1 are located in the same assembly.
Upvotes: 65
Views: 41467
Reputation: 36438
See the docs which state that it can be used on classes, structs or interfaces.
Upvotes: 2
Reputation: 27374
Think twice before making your interface partial. Maybe it's better to split it into two interfaces?
Keep your interfaces small and focused. partial is a code smell.
Upvotes: 5
Reputation: 38378
Partial Classes and Methods (C# Programming Guide) at MSDN
partial
.interface
.Partial interfaces are primary used when code generation is involved. For example when one part of an interface is generated and the other one is user-written.
Upvotes: 9
Reputation: 39
Nice.
I agree this could be a smell, but I can still think of one reason to do it.
I'm currently working on an application MVVM framework for WPF and Silverlight. What I've encountered is that WPF and Silverlight are so different that rather than using defines all over the code, the partial interface/class can actually separate the differences between the two frameworks and still keep the code clean and nearly single sourced.
Upvotes: 3
Reputation: 1500835
The simplest way is just to try it :)
But yes, partial interfaces are allowed.
Valid locations for the partial
modifier (with C# 3.0 spec references):
Section 10.2 of the spec contains most of the general details for partial types.
Invalid locations:
Upvotes: 102
Reputation: 178680
Yes, it does. Are both partial interfaces defined in the same namespace?
Upvotes: 2
Reputation: 155692
It does, but an important question would be why?
Partial classes are there so that you can extend auto-generated code. VS can generate a form file, or code behind, or Linq to SQL accessor and you can extend it using a partial.
I'd avoid using partials just to split up classes (or in this case interfaces) as generally that generates more confusion than it's worth.
In this case I'd investigate why this needs to be across multiple files - factory pattern interfaces can make tracking back through you code more complex, but here you'd be tracking back through multiple files.
Upvotes: 7