Example #1
0
        protected override void DoWrite(object obj, Hessian2Writer writer)
        {
            var type = obj.GetType();

            if (type.IsGenericType)
            {
                var genericType = type.GetGenericTypeDefinition();
                writer.WriteMapBegin(genericType == typeof(Dictionary <,>)
                    ? null
                    : SerializeFactory.GetMapType(genericType.AssemblyQualifiedName));
            }
            else
            {
                writer.WriteMapBegin(obj is Hashtable ? null : type.AssemblyQualifiedName);
            }

            var dic = (IDictionary)obj;

            foreach (DictionaryEntry kv in dic)
            {
                writer.WriteObject(kv.Key);
                writer.WriteObject(kv.Value);
            }
            writer.WriteMapEnd();
        }
Example #2
0
        protected override bool WriteListBegin(object obj, Hessian2Writer writer)
        {
            var listType   = obj.GetType();
            var collection = (ICollection)obj;

            if (listType.IsGenericType)
            {
                var genericType = listType.GetGenericTypeDefinition();
                writer.WriteListStart(collection.Count,
                                      genericType == typeof(List <>)
                        ? null
                        : SerializeFactory.GetMapType(genericType.AssemblyQualifiedName));
            }
            else
            {
                writer.WriteListStart(collection.Count, collection is ArrayList ? null : listType.AssemblyQualifiedName);
            }
            return(false);
        }