Beispiel #1
0
        /// <summary>
        /// Serialiaztion of objects
        /// </summary>
        /// <param name="obj">Object to serialize</param>
        /// <param name="abstractHessianOutput">HessianOutput - Instance</param>
        public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput)
        {
            if (abstractHessianOutput.AddRef(obj))
            {
                return;
            }

            var ds = obj as DataSet;

            abstractHessianOutput.WriteMapBegin(obj.GetType().FullName);
            foreach (DataTable dt in ds.Tables)
            {
                abstractHessianOutput.WriteMapBegin(null);
                abstractHessianOutput.WriteString(dt.TableName);
                foreach (DataColumn column in dt.Columns)
                {
                    abstractHessianOutput.WriteString(column.ColumnName);
                    abstractHessianOutput.WriteString(column.DataType.FullName);
                }
                abstractHessianOutput.WriteMapEnd();

                abstractHessianOutput.WriteMapBegin(null);
                foreach (DataRow dr in dt.Rows)
                {
                    abstractHessianOutput.WriteMapBegin(null);
                    foreach (object value in dr.ItemArray)
                    {
                        abstractHessianOutput.WriteObject(value);
                    }
                    abstractHessianOutput.WriteMapEnd();
                }
                abstractHessianOutput.WriteMapEnd();
            }
            abstractHessianOutput.WriteMapEnd();
        }
        /// <summary>
        /// Writes map in the output stream
        /// </summary>
        /// <param name="obj"> Object to write</param>
        /// <param name="abstractHessianOutput">Instance of the hessian output</param>
        public override void WriteObject(object obj, AbstractHessianOutput abstractHessianOutput)
        {
            if (abstractHessianOutput.AddRef(obj))
            {
                return;
            }

            IDictionary dictionary = (IDictionary)obj;


            Type mapType = obj.GetType();

            if (mapType.Equals(typeof(Hashtable)))
            {
                abstractHessianOutput.WriteMapBegin(null);
            }
            else
            {
                abstractHessianOutput.WriteMapBegin(mapType.Name);
            }

            IDictionaryEnumerator enumerator = dictionary.GetEnumerator();

            while (enumerator.MoveNext())
            {
                object objKey = enumerator.Key;

                abstractHessianOutput.WriteObject(objKey);

                object objValue = enumerator.Value;

                abstractHessianOutput.WriteObject(objValue);
            }
            abstractHessianOutput.WriteMapEnd();
        }