Example #1
0
 public void WriteAMF3Data(object data)
 {
     if (data == null)
     {
         this.WriteAMF3Null();
     }
     else if (data is DBNull)
     {
         this.WriteAMF3Null();
     }
     else
     {
         if (FluorineConfiguration.Instance.AcceptNullValueTypes && (FluorineConfiguration.Instance.NullableValues != null))
         {
             Type type = data.GetType();
             if (FluorineConfiguration.Instance.NullableValues.ContainsKey(type) && data.Equals(FluorineConfiguration.Instance.NullableValues[type]))
             {
                 this.WriteAMF3Null();
                 return;
             }
         }
         IAMFWriter writer = null;
         if (AmfWriterTable[3].ContainsKey(data.GetType()))
         {
             writer = AmfWriterTable[3][data.GetType()];
         }
         if ((writer == null) && AmfWriterTable[3].ContainsKey(data.GetType().BaseType))
         {
             writer = AmfWriterTable[3][data.GetType().BaseType];
         }
         if (writer == null)
         {
             lock (AmfWriterTable)
             {
                 if (!AmfWriterTable[3].ContainsKey(data.GetType()))
                 {
                     writer = new AMF3ObjectWriter();
                     AmfWriterTable[3].Add(data.GetType(), writer);
                 }
                 else
                 {
                     writer = AmfWriterTable[3][data.GetType()];
                 }
             }
         }
         if (writer == null)
         {
             throw new FluorineException(string.Format("Could not find serializer for type {0}", data.GetType().FullName));
         }
         writer.WriteData(this, data);
     }
 }
Example #2
0
        public void WriteAMF3Data(object data)
        {
            if (data == null)
            {
                WriteAMF3Null();

                return;
            }

            if (data is DBNull)
            {
                WriteAMF3Null();

                return;
            }

            Type type = data.GetType();

            IAMFWriter amfWriter = null;

            if (AmfWriterTable[3].ContainsKey(type))
            {
                amfWriter = AmfWriterTable[3][type] as IAMFWriter;
            }

            if (amfWriter == null)
            {
                if (type.BaseType != null)
                {
                    if (AmfWriterTable[3].ContainsKey(type.BaseType))
                    {
                        amfWriter = AmfWriterTable[3][type.BaseType] as IAMFWriter;
                    }
                }
            }

            if (amfWriter == null)
            {
                amfWriter = new AMF3ObjectWriter();
            }

            amfWriter.WriteData(this, data);
        }