Interface and partial classes
Posted
by Tomek Tarczynski
on Stack Overflow
See other posts from Stack Overflow
or by Tomek Tarczynski
Published on 2010-04-10T15:52:49Z
Indexed on
2010/04/10
16:13 UTC
Read the original article
Hit count: 380
According to rule SA1201 in StyleCop elements in class must appear in correct order.
The order is following:
Fields
Constructors
Finalizers (Destructors)
Delegates
Events
Enums
Interfaces
Properties
Indexers
Methods
Structs
Classes
Everything is ok, except of Interfaces part, because Interface can contain mehtods, events, properties etc...
If we want to be strict about this rule then we won't have all members of Interface in one place which is often very useful. According to StyleCop help this problem can be solved by spliting class into partial classes.
Example:
/// <summary>
/// Represents a customer of the system.
/// </summary>
public partial class Customer
{
// Contains the main functionality of the class.
}
/// <content>
/// Implements the ICollection class.
/// </content>
public partial class Customer : ICollection
{
public int Count
{
get { return this.count; }
}
public bool IsSynchronized
{
get { return false; }
}
public object SyncRoot
{
get { return null; }
}
public void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
}
Are there any other good solutions to this problem?
© Stack Overflow or respective owner