StyleCop のルール SA1201 によると、クラス内の要素は正しい順序で表示される必要があります。
順序は次のとおりです。
Fields
Constructors
Finalizers (Destructors)
Delegates
Events
Enums
Interfaces
Properties
Indexers
Methods
Structs
Classes
Interface にはメソッド、イベント、プロパティなどを含めることができるため、Interfaces 部分を除い
てすべて問題ありません。このルールを厳密に適用したい場合は、Interface のすべてのメンバーを 1 か所に配置する必要はありません。これは非常に便利です。StyleCop のヘルプによると、この問題はクラスを部分クラスに分割することで解決できます。
例:
/// <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();
}
}
この問題に対する他の良い解決策はありますか?