private void HandleComplexTypePSObject
        (
            object source,
            string property,
            int depth,
            out CimInstance result
        )
        {
            List <CimInstance> listOfCimInstancesProperties = null;

            Dbg.Assert(source != null, "caller should validate the parameter");
            PSObject mshSource = PSObject.AsPSObject(source);

            // Figure out what kind of object we are dealing with
            bool isErrorRecord         = false;
            bool isInformationalRecord = false;
            bool isEnum     = false;
            bool isPSObject = false;

            //TODO, insivara : To be implemented
            //bool isCimInstance = false;

            if (!mshSource.immediateBaseObjectIsEmpty)
            {
                ErrorRecord errorRecord = mshSource.ImmediateBaseObject as ErrorRecord;
                if (errorRecord == null)
                {
                    InformationalRecord informationalRecord = mshSource.ImmediateBaseObject as InformationalRecord;
                    if (informationalRecord == null)
                    {
                        isEnum     = mshSource.ImmediateBaseObject is Enum;
                        isPSObject = mshSource.ImmediateBaseObject is PSObject;
                    }
                    else
                    {
                        informationalRecord.ToPSObjectForRemoting(mshSource);
                        isInformationalRecord = true;
                    }
                }
                else
                {
                    errorRecord.ToPSObjectForRemoting(mshSource);
                    isErrorRecord = true;
                }
            }

            bool writeToString = true;

            if (mshSource.ToStringFromDeserialization == null)
            // continue to write ToString from deserialized objects, but...
            {
                if (mshSource.immediateBaseObjectIsEmpty) // ... don't write ToString for property bags
                {
                    writeToString = false;
                }
            }

            // This will create a CimInstance for PS_Object and populate the typenames.
            result = CreateCimInstanceForPSObject(cimClassName: "PS_Object",
                                                  psObj: mshSource,
                                                  writeToString: writeToString);

            PSMemberInfoInternalCollection <PSPropertyInfo> specificPropertiesToSerialize =
                SerializationUtilities.GetSpecificPropertiesToSerialize(mshSource, AllPropertiesCollection, _typeTable);

            if (isEnum)
            {
                CimInstance enumCimInstance = CreateCimInstanceForEnum(mshSource, depth, property != null);
                CimProperty p = CimProperty.Create("Value", enumCimInstance,
                                                   Microsoft.Management.Infrastructure.CimType.Reference,
                                                   Microsoft.Management.Infrastructure.CimFlags.Property);
                result.CimInstanceProperties.Add(p);
            }
            else if (isPSObject)
            {
                CimInstance psObjectCimInstance;
                CreateCimInstanceForOneObject(mshSource.ImmediateBaseObject, property, depth, out psObjectCimInstance);
                CimProperty valueProperty = CimProperty.Create("Value", psObjectCimInstance,
                                                               Microsoft.Management.Infrastructure.CimType.Reference,
                                                               Microsoft.Management.Infrastructure.CimFlags.Property);
                result.CimInstanceProperties.Add(valueProperty);
            }
            else if (isErrorRecord || isInformationalRecord)
            {
                // nothing to do
            }
            else
            {
                CreateCimInstanceForPSObjectProperties(mshSource, depth, specificPropertiesToSerialize, out listOfCimInstancesProperties);
            }

            //TODO, insivara : Implement serialization of CimInstance
            //if (isCimInstance)
            //{
            //    CimInstance cimInstance = mshSource.ImmediateBaseObject as CimInstance;
            //    PrepareCimInstanceForSerialization(mshSource, cimInstance);
            //}

            //TODO, insivara : ExtendedProperties implementation will be done in a subsequent checkin
            //SerializeExtendedProperties(mshSource, depth, specificPropertiesToSerialize, out listOfCimInstancesExtendedProperties);

            if (listOfCimInstancesProperties != null && listOfCimInstancesProperties.Count > 0)
            {
                CimInstance[] referenceArray = listOfCimInstancesProperties.ToArray();
                CimProperty   properties     = CimProperty.Create("Properties", referenceArray,
                                                                  Microsoft.Management.Infrastructure.CimType.ReferenceArray,
                                                                  Microsoft.Management.Infrastructure.CimFlags.Property);
                result.CimInstanceProperties.Add(properties);
            }
        }