Example #1
0
        public void Write(BinaryWriter writer, object obj)
        {
            int index = 0;

            if (obj != null)
            {
                for (; index < ((Array)obj).Length; ++index)
                {
                    object obj1 = ((Array)obj).GetValue(index);
                    m_UnderlyingPersistor.Write(writer, obj1);
                }
            }

            if (index >= m_DataField.Length)
            {
                return;
            }
            Type   actualMemberType = m_DataField.ActualMemberType;
            object obj2             = !(actualMemberType == typeof(string))
        ? Activator.CreateInstance(actualMemberType)
        : "";

            for (; index < m_DataField.Length; ++index)
            {
                m_UnderlyingPersistor.Write(writer, obj2);
            }
        }
Example #2
0
        //public int BinaryLength
        //{
        //    get { return m_UnderlyingPersistor.BinaryLength * m_DataField.Length; }
        //}

        public void Write(BinaryWriter writer, object obj)
        {
            var i = 0;

            if (obj != null)
            {
                for (; i < ((Array)obj).Length; i++)
                {
                    var item = ((Array)obj).GetValue(i);
                    m_UnderlyingPersistor.Write(writer, item);
                }
            }

            if (i < m_DataField.Length)
            {
                // write default Item as a filler
                var type = m_DataField.ActualMemberType;

                object deflt;
                if (type == typeof(string))
                {
                    deflt = "";
                }
                else
                {
                    deflt = Activator.CreateInstance(type);
                }

                for (; i < m_DataField.Length; i++)
                {
                    m_UnderlyingPersistor.Write(writer, deflt);
                }
            }
        }
Example #3
0
 public void Write(BinaryWriter writer, object obj)
 {
     if (obj == null)
     {
         obj = this.m_DataField.Producer.Produce();
     }
     for (int index = 0; index < this.m_UnderlyingPersistors.Length; ++index)
     {
         IBinaryPersistor underlyingPersistor = this.m_UnderlyingPersistors[index];
         object           obj1 = this.m_accessors[index].Get(obj);
         underlyingPersistor.Write(writer, obj1);
     }
 }
Example #4
0
 private void Write(BinaryWriter writer, IDataHolder holder)
 {
     for (int index = 0; index < m_persistors.Length; ++index)
     {
         IBinaryPersistor persistor = m_persistors[index];
         try
         {
             object obj = m_fields[index].Accessor.Get(holder);
             persistor.Write(writer, obj);
         }
         catch (Exception ex)
         {
             throw new DataHolderException(ex,
                                           "Failed to write DataHolder \"{0}\" (Persistor #{1} {2} for: {3}).", (object)holder, (object)index,
                                           (object)persistor, (object)m_fields[index]);
         }
     }
 }