Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial Interface in C#

Tags:

c#

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.

like image 512
Graviton Avatar asked Apr 09 '09 13:04

Graviton


People also ask

What is partial interface?

In C#, you can split the implementation of an interface into multiple files using the partial keyword. The partial keyword indicates that other parts of the interface can be defined anywhere in the namespace.

Can interface be partial in C#?

But yes, partial interfaces are allowed. Valid locations for the partial modifier (with C# 3.0 spec references): Classes (10.1.

Can a partial class implement an interface?

Partial class, interface and structure was introduced in C# 2.0. Now it is possible to split the definition of an class, interface and structure over more than one source files. Moreover the other parts of the class, struct, or interface should be defined in the same namespace or assembly.

What is the use of partial class?

Partial Class is a unique feature of C#. It can break the functionality of a single class into many files. When the application is compiled, these files are then reassembled into a single class file. The partial keyword is used to build a partial class.


1 Answers

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):

  • Classes (10.1.2)
  • Structs (11.1.2)
  • Interfaces (13.1.2)
  • Methods (C# 3.0+) (10.2.7; 10.6.8)

Section 10.2 of the spec contains most of the general details for partial types.

Invalid locations:

  • Enums
  • Delegates
like image 124
Jon Skeet Avatar answered Oct 08 '22 21:10

Jon Skeet