bool PdxInstanceImpl::Equals()

in clicache/src/impl/PdxInstanceImpl.cpp [211:371]


        bool PdxInstanceImpl::Equals(Object^ other)
        {
          if (other == nullptr)
            return false;

          PdxInstanceImpl^ otherPdx = dynamic_cast<PdxInstanceImpl^>(other);

          if (otherPdx == nullptr)
            return false;

          PdxType^ myPdxType = getPdxType();
          PdxType^ otherPdxType = otherPdx->getPdxType();

          if (!otherPdxType->PdxClassName->Equals(myPdxType->PdxClassName))
            return false;

          int hashCode = 1;

          //PdxType^ pt = getPdxType();

          IList<PdxFieldType^>^ myPdxIdentityFieldList = getIdentityPdxFields(myPdxType);
          IList<PdxFieldType^>^ otherPdxIdentityFieldList = otherPdx->getIdentityPdxFields(otherPdxType);

          equatePdxFields(myPdxIdentityFieldList, otherPdxIdentityFieldList);
          equatePdxFields(otherPdxIdentityFieldList, myPdxIdentityFieldList);

          DataInput^ myDataInput = gcnew DataInput(m_buffer, m_bufferLength, m_cache);
          myDataInput->setPdxdeserialization(true);
          DataInput^ otherDataInput = gcnew DataInput(otherPdx->m_buffer, otherPdx->m_bufferLength, m_cache);
          otherDataInput->setPdxdeserialization(true);

          bool isEqual = false;
          int fieldTypeId = -1;
          for (int i = 0; i < myPdxIdentityFieldList->Count; i++)
          {
            PdxFieldType^ myPFT = myPdxIdentityFieldList[i];
            PdxFieldType^ otherPFT = otherPdxIdentityFieldList[i];

            // Log::Debug("pdxfield " + ((myPFT != Default_PdxFieldType)? myPFT->FieldName: otherPFT->FieldName));
            if (myPFT == Default_PdxFieldType)
            {
              fieldTypeId = otherPFT->TypeId;
              /*Object^ val = otherPdx->GetField(otherPFT->FieldName);
              if(val == nullptr || (int)val == 0 || (bool)val == false)
              continue;*/
            }
            else if (otherPFT == Default_PdxFieldType)
            {
              fieldTypeId = myPFT->TypeId;
              /*Object^ val = this->GetField(myPFT->FieldName);
              if(val == nullptr || (int)val == 0 || (bool)val == false)
              continue;*/
            }
            else
            {
              fieldTypeId = myPFT->TypeId;
            }

            switch (fieldTypeId)
            {
            case PdxFieldTypes::CHAR:
            case PdxFieldTypes::BOOLEAN:
            case PdxFieldTypes::BYTE:
            case PdxFieldTypes::SHORT:
            case PdxFieldTypes::INT:
            case PdxFieldTypes::LONG:
            case PdxFieldTypes::DATE:
            case PdxFieldTypes::FLOAT:
            case PdxFieldTypes::DOUBLE:
            case PdxFieldTypes::STRING:
            case PdxFieldTypes::BOOLEAN_ARRAY:
            case PdxFieldTypes::CHAR_ARRAY:
            case PdxFieldTypes::BYTE_ARRAY:
            case PdxFieldTypes::SHORT_ARRAY:
            case PdxFieldTypes::INT_ARRAY:
            case PdxFieldTypes::LONG_ARRAY:
            case PdxFieldTypes::FLOAT_ARRAY:
            case PdxFieldTypes::DOUBLE_ARRAY:
            case PdxFieldTypes::STRING_ARRAY:
            case PdxFieldTypes::ARRAY_OF_BYTE_ARRAYS:
            {
              if (!compareRawBytes(otherPdx, myPdxType, myPFT, myDataInput, otherPdxType, otherPFT, otherDataInput))
                return false;
              break;
            }
            case PdxFieldTypes::OBJECT:
            {
              Object^ object = nullptr;
              Object^ otherObject = nullptr;
              if (myPFT != Default_PdxFieldType)
              {
                setOffsetForObject(myDataInput, myPdxType, myPFT->SequenceId);
                object = myDataInput->ReadObject();
              }

              if (otherPFT != Default_PdxFieldType)
              {
                otherPdx->setOffsetForObject(otherDataInput, otherPdxType, otherPFT->SequenceId);
                otherObject = otherDataInput->ReadObject();
              }


              if (object != nullptr)
              {
                if (object->GetType()->IsArray)
                {
                  if (object->GetType()->GetElementType()->IsPrimitive)//primitive type
                  {
                    if (!compareRawBytes(otherPdx, myPdxType, myPFT, myDataInput, otherPdxType, otherPFT, otherDataInput))
                      return false;
                  }
                  else//array of objects
                  {
                    if (!deepArrayEquals(object, otherObject))
                      return false;
                  }
                }
                else//object but can be hashtable, list etc
                {
                  if (!deepArrayEquals(object, otherObject))
                    return false;
                }
              }
              else if (otherObject != nullptr)
              {
                return false;
                //hashCode = 31 * hashCode; // this may be issue 
              }

              break;
            }
            case PdxFieldTypes::OBJECT_ARRAY:
            {
              Object^ objectArray = nullptr;
              Object^ otherObjectArray = nullptr;

              if (myPFT != Default_PdxFieldType)
              {
                setOffsetForObject(myDataInput, myPdxType, myPFT->SequenceId);
                objectArray = myDataInput->ReadObjectArray();
              }

              if (otherPFT != Default_PdxFieldType)
              {
                otherPdx->setOffsetForObject(otherDataInput, otherPdxType, otherPFT->SequenceId);
                otherObjectArray = otherDataInput->ReadObjectArray();
              }

              if (!deepArrayEquals(objectArray, otherObjectArray))
                return false;
              break;
            }
            default:
            {
              throw gcnew IllegalStateException("PdxInstance not found typeid " + myPFT->TypeId);
            }
            }

          }
          return true;
        }