IEnumerableConverter.cs
上传用户:szgaoree
上传日期:2009-01-05
资源大小:74k
文件大小:1k
- using System;
- using System.Reflection;
- using System.Text;
- using System.Collections;
- using System.Collections.Specialized;
- namespace AjaxPro
- {
- /// <summary>
- /// Provides methods to serialize and deserialize an object that implements IEnumerable.
- /// </summary>
- public class IEnumerableConverter : IJavaScriptConverter
- {
- public IEnumerableConverter() : base()
- {
- }
- public override string Serialize(object o)
- {
- if(!(o is IEnumerable))
- throw new NotSupportedException();
- StringBuilder sb = new StringBuilder();
- IEnumerable enumerable = (IEnumerable)o;
- bool b = true;
- sb.Append("[");
-
- foreach(object obj in enumerable)
- {
- if(b){ b = false; }
- else{ sb.Append(","); }
- sb.Append(JavaScriptSerializer.Serialize(obj));
- }
- sb.Append("]");
- return sb.ToString();
- }
- public override Type[] SerializableTypes
- {
- get
- {
- return new Type[]{typeof(IEnumerable)};
- }
- }
- }
- }