Beispiel #1
0
        /// <summary>
        ///     Encodes the object specified.
        /// </summary>
        /// <param name="encoderInfo">
        ///     The encoder info.
        /// </param>
        /// <param name="value">
        ///     The object to encode.
        /// </param>
        /// <param name="writeTag">
        ///     If <c>true</c> the encoder writes the leading type tag, otherwise <c>false</c>.
        /// </param>
        internal override void Encode(EncoderInfo encoderInfo, object value, bool writeTag)
        {
            if (value != null)
            {
                var anyType = value.GetType();
                if (encoderInfo.HandleObjectRef(anyType))
                {
                    if (this.WriteOrAddObjectRef(value))
                    {
                        return;
                    }

                    var inspector       = Inspector.InspectorForType(anyType);
                    var entityReference = this.entityContext.EntityReferenceForInspector(inspector);

                    // Entity?
                    if (entityReference != null && this.SerializeEntityReference(entityReference, anyType, value))
                    {
                        return;
                    }
                }
            }

            encoderInfo.Encode(this, value, writeTag);
        }
Beispiel #2
0
        /// <summary>
        ///     Encodes the specified property.
        /// </summary>
        /// <param name="serializer">
        ///     The serializer.
        /// </param>
        /// <param name="inspectedProperty">
        ///     The inspected property.
        /// </param>
        /// <param name="encoderInfo">
        ///     The encoder info.
        /// </param>
        /// <param name="any">
        ///     The object to which the property belongs.
        /// </param>
        private static void EncodeProperty(Serializer serializer, InspectedProperty inspectedProperty,
                                           EncoderInfo encoderInfo, object any)
        {
            var value = inspectedProperty.Getter(any);

            if (value == null)
            {
                Encoder.WriteTag(serializer.BinaryWriter, Tags.Null);
            }
            else
            {
                serializer.Encode(encoderInfo, value, true);
            }
        }
Beispiel #3
0
 /// <summary>
 /// Attempts to get the encoder info associated with the type.
 /// </summary>
 /// <param name="type">
 /// The type.
 /// </param>
 /// <param name="encoderInfo">
 /// The encoder Info.
 /// </param>
 /// <returns>
 /// <c>true</c> if the decoder info exists for the tag specified, otherwise <c>false</c>.
 /// </returns>
 internal static bool TryGetEncoder(Type type, out EncoderInfo encoderInfo)
 {
     return EncoderInfos.TryGetValue(type, out encoderInfo);
 }
Beispiel #4
0
 /// <summary>
 /// Encodes the specified property.
 /// </summary>
 /// <param name="serializer">
 /// The serializer.
 /// </param>
 /// <param name="inspectedProperty">
 /// The inspected property.
 /// </param>
 /// <param name="encoderInfo">
 /// The encoder info.
 /// </param>
 /// <param name="any">
 /// The object to which the property belongs.
 /// </param>
 private static void EncodeProperty(Serializer serializer, InspectedProperty inspectedProperty, EncoderInfo encoderInfo, object any)
 {
     var value = inspectedProperty.Getter(any);
     if (value == null)
     {
         Encoder.WriteTag(serializer.BinaryWriter, Tags.Null);
     }
     else
     {
         serializer.Encode(encoderInfo, value, true);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Encodes the object specified.
        /// </summary>
        /// <param name="encoderInfo">
        /// The encoder info.
        /// </param>
        /// <param name="value">
        /// The object to encode.
        /// </param>
        /// <param name="writeTag">
        /// If <c>true</c> the encoder writes the leading type tag, otherwise <c>false</c>.
        /// </param>
        internal override void Encode(EncoderInfo encoderInfo, object value, bool writeTag)
        {
            if (value != null)
            {
                var anyType = value.GetType();
                if (encoderInfo.HandleObjectRef(anyType))
                {
                    if (this.WriteOrAddObjectRef(value))
                    {
                        return;
                    }

                    var inspector = Inspector.InspectorForType(anyType);
                    var entityReference = this.entityContext.EntityReferenceForInspector(inspector);

                    // Entity?
                    if (entityReference != null && this.SerializeEntityReference(entityReference, anyType, value))
                    {
                        return;
                    }
                }
            }

            encoderInfo.Encode(this, value, writeTag);
        }