public bool Equals(Variant v) {
int cvtype = CVType;
if (cvtype == CV_ENUM) {
if (v.CVType != CV_ENUM || v.m_objref != m_objref)
return false;
cvtype = MapEnumToCVType(EnumType);
}
else {
if (v.CVType != cvtype) {
return false;
}
}
switch (cvtype) {
case CV_BOOLEAN:
return m_data1==v.m_data1;
case CV_I1:
case CV_U1:
return ((byte)m_data1==(byte)v.m_data1);
case CV_I2:
case CV_U2:
case CV_CHAR:
return ((short)m_data1==(short)v.m_data1);
case CV_I4:
case CV_U4:
return (m_data1==v.m_data1);
case CV_I8:
case CV_U8:
case CV_DATETIME:
case CV_TIMESPAN:
case CV_CURRENCY:
// Bitwise equality is correct for all these types.
return (m_data1==v.m_data1 && m_data2==v.m_data2);
case CV_R4:
// For R4 and R8, must compare as fp values to handle Not-a-Number.
return GetR4FromVar()==v.GetR4FromVar();
case CV_R8:
// For R4 and R8, must compare as fp values to handle Not-a-Number.
return GetR8FromVar()==v.GetR8FromVar();
case CV_STRING:
case CV_DECIMAL:
case CV_OBJECT:
// If we have a null objref, it is equal to another object
// iff the other object is null.
if (m_objref==null)
return (v.m_objref==null);
return m_objref.Equals(v.m_objref);
case CV_EMPTY:
case CV_MISSING:
// Missing is a "flag" Variant that can't be directly instantiated.
// Therefore two missings are always equal.
return true;
case CV_NULL:
// Spec now says database NULL's never equal one another.
return false;
default:
return false;
}
}