I know that template specializtion is not included in generics, but
was wondering whether or not there is an elegant alternative?

The first function is always called, but I was hoping that for
instances of type RealPoint (ComparePointByFiaNumber<RealPoint)>) the
second function would be called.

To implement different behavious based upon the type, do I have to
have a switch within Equals() that will check the type of T and then
call different functions as needed?

Many thanks,

Duncan

generic<typename T>
ref class ComparePointByFiaNumber : Generic::IEqualityComparer<T>
{
public:

virtual bool Equals( T x, T y )
{
Generic::IEqualityComparer<T>^ equalityComparer =
Generic::EqualityComparer<T>::Default;
return equalityComparer->Equals( x,y );
}

virtual bool Equals( RealPoint^ x, RealPoint^ y )
{
return true;
}

Re: Equivalent of template specialization using .NET Generics? by Duncan

Duncan
Thu May 08 08:40:07 CDT 2008

On May 8, 1:16=A0pm, Duncan Smith <DSmith1...@googlemail.com> wrote:
> I know that template specializtion is not included in generics, but
> was wondering whether or not there is an elegant alternative?
>

Not as pretty as C++ but in the end I went for:

generic<typename T>
ref class ComparePointByFiaNumber : Generic::IEqualityComparer<T>
{
public:

virtual bool Equals( T x, T y )
{
if( x->GetType() =3D=3D RealPoint::typeid )
{
return safe_cast<RealPoint^>(x)->First =3D=3D
safe_cast<RealPoint^>(y)->First;
}

Generic::IEqualityComparer<T>^ equalityComparer =3D
Generic::EqualityComparer<T>::Default;
return equalityComparer->Equals( x,y );
}

virtual int GetHashCode( T obj )
{
return 0;
}
};