1

私はグリッド UserControl を持っています。IFormatProvider を使用して、セル内のテキストを表示用にフォーマットしました。各セルは、独自の IFormatProvider を設定できます。セルの DisplayText の要求に応じて、プログラムは Cell の IFormatProvider、次に Column の IFormatProvider を順番に呼び出します。形式を取得するために ID を保存するだけでよいように、すべての同一でない IFormatProvider を保存する配列を作成します。

IFormatProvider を比較する方法は? 異なる場合は、配列に保存します。

private IFormatProvider[] FormatProviders;

internal short CreateNewFormatProviders(IFormatProvider newFormatProvider)
{
    if (newFormatProvider == null) // (IFormatProvider.Equals(newFormatProvider,null))
    {
        return -1;
    }
    int len = this.FormatProviders.Length;
    for (int i = 0; i < len; i++)
    {
        if (IFormatProvider.Equals(this.FormatProviders[i],newFormatProvider))
        {
            return (short)i;
        }
    }
    Array.Resize<IFormatProvider>(ref this.FormatProviders, len + 1);
    this.FormatProviders[len] = newFormatProvider;
    return (short)len;
}        

上記のコードでは、IFormatProvider.Equals を使用しました。それは機能していますか、それともより良い方法がありますか?

4

1 に答える 1