NeedsHashCode() public method

public NeedsHashCode ( Object obj ) : bool
obj Object
return bool
Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="outputBuffer"></param>
        /// <param name="translationContext"></param>
        /// <param name="allFieldDescriptors"></param>
        private void SerializeFields(object obj, BinaryWriter outputBuffer, TranslationContext translationContext, IList<FieldDescriptor> allFieldDescriptors)
        {
            if (SimplTypesScope.graphSwitch == SimplTypesScope.GRAPH_SWITCH.ON)
            {
                if (translationContext.NeedsHashCode(obj))
                {
                    WriteSimplIdAttribute(obj, outputBuffer);
                }
            }

            foreach (FieldDescriptor childFd in allFieldDescriptors)
            {
                MemoryStream memoryStreamCollection = new MemoryStream();
                BinaryWriter collectionBuffer = new BinaryWriter(memoryStreamCollection);

                switch (childFd.FdType)
                {
                    case FieldTypes.Scalar:
                        WriteValue(obj, childFd, outputBuffer, translationContext);
                        break;
                    case FieldTypes.CompositeElement:
                        Object compositeObject = childFd.GetObject(obj);
                        FieldDescriptor compositeObjectFieldDescriptor = childFd.IsPolymorphic
                                                                             ? GetClassDescriptor(
                                                                                 compositeObject).PseudoFieldDescriptor
                                                                             : childFd;

                        WriteWrap(childFd, outputBuffer, memoryStreamCollection);
                        Serialize(compositeObject, compositeObjectFieldDescriptor, outputBuffer, translationContext);
                        WriteWrap(childFd, outputBuffer, memoryStreamCollection);
                        break;
                    case FieldTypes.CollectionScalar:
                    case FieldTypes.MapScalar:
                        Object scalarCollectionObject = childFd.GetObject(obj);
                        ICollection scalarCollection = XmlTools.GetCollection(scalarCollectionObject);
                        foreach (Object collectionObject in scalarCollection)
                        {
                            WriteScalarCollectionLeaf(collectionObject, childFd, collectionBuffer, translationContext);
                        }
                        WriteWrap(childFd, outputBuffer, memoryStreamCollection);
                        break;
                    case FieldTypes.CollectionElement:
                    case FieldTypes.MapElement:
                        Object compositeCollectionObject = childFd.GetObject(obj);
                        ICollection compositeCollection = XmlTools.GetCollection(compositeCollectionObject);
                        foreach (Object collectionComposite in compositeCollection)
                        {
                            FieldDescriptor collectionObjectFieldDescriptor = childFd.IsPolymorphic
                                                                                  ? GetClassDescriptor(
                                                                                      collectionComposite).
                                                                                        PseudoFieldDescriptor
                                                                                  : childFd;
                            Serialize(collectionComposite, collectionObjectFieldDescriptor, collectionBuffer,
                                      translationContext);
                        }
                        WriteWrap(childFd, outputBuffer, memoryStreamCollection);
                        break;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="textWriter"></param>
        /// <param name="translationContext"></param>
        /// <param name="allFieldDescriptors"></param>
        private void SerializeFields(object obj, TextWriter textWriter, TranslationContext translationContext, ClassDescriptor cd)
        {
            List<FieldDescriptor> allFieldDescriptors = cd.AllFieldDescriptors.ToList();

            if(SimplTypesScope.graphSwitch == SimplTypesScope.GRAPH_SWITCH.ON)
            {
                if(translationContext.NeedsHashCode(obj))
                {
                    WriteSimplIdAttribute(obj, textWriter, allFieldDescriptors.Count <= 0, translationContext);
                }
            }

            List<FieldDescriptor> attributeFieldDescriptors = cd.AttributeFieldDescriptors as List<FieldDescriptor>;
            int numOfFields = SerializeFieldsHelper(textWriter, obj, translationContext, attributeFieldDescriptors, 0);
            List<FieldDescriptor> elementFieldDescriptors = cd.ElementFieldDescriptors;
            SerializeFieldsHelper(textWriter, obj, translationContext, elementFieldDescriptors,numOfFields);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="textWriter"></param>
        /// <param name="translationContext"></param>
        /// <param name="rootObjectClassDescrpitor"></param>
        private void SerializedAttributes(object obj, TextWriter textWriter, TranslationContext translationContext, ClassDescriptor rootObjectClassDescrpitor)
        {
            List<FieldDescriptor> attributeFieldDescriptors = rootObjectClassDescrpitor
                .AttributeFieldDescriptors;

            foreach (FieldDescriptor childFd in attributeFieldDescriptors)
            {
                try
                {
                    WriteValueAsAtrribute(obj, childFd, textWriter, translationContext);
                }
                catch (Exception ex)
                {
                    throw new Exception("serialize for attribute " + obj, ex);
                }
            }

            if (SimplTypesScope.graphSwitch == SimplTypesScope.GRAPH_SWITCH.ON)
            {
                if (translationContext.NeedsHashCode(obj))
                {
                    WriteSimplIdAttribute(obj, textWriter, translationContext);
                }

                if (_isRoot && translationContext.IsGraph)
                {
                    WriteSimplNameSpace(textWriter);
                    _isRoot = false;
                }
            }
        }