コード例 #1
0
ファイル: DataWriter`1.cs プロジェクト: V1046-R/ShipGirlBot
        /// <summary>
        /// Serializes the data to the given output
        /// </summary>
        /// <param name="data">the data to be serialized</param>
        /// <returns>the serialized data</returns>
        public virtual string Write(object data)
        {
            IObjectWalker <T> walker = this.GetWalker();

            if (walker == null)
            {
                throw new ArgumentNullException("walker");
            }

            ITextFormatter <T> formatter = this.GetFormatter();

            if (formatter == null)
            {
                throw new ArgumentNullException("formatter");
            }

            try
            {
                // objects => tokens => characters
                return(formatter.Format(walker.GetTokens(data)));
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new SerializationException(ex.Message, ex);
            }
        }