I have an Grid UserControl. It used IFormatProvider to format Text in a Cell for display. Each Cell allows to set own IFormatProvider. On request of cell's DisplayText, program calls Cell's IFormatProvider, then Column's IFormatProvider in order. I make an array to save all non-identical IFormatProvider so that I just need to save ID to retrieve the format.
How to compare the IFormatProvider? If they are different, save into the array.
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;
}
In above code, I used IFormatProvider.Equals. Is it functioning or has better way?