예제 #1
9
 public static Array ToArray(Mixed m)
 {
     if (m is Boolean) {
         Array a = new Array();
         a.Append(m);
         return a;
     }
     else if (m is Integer) {
         Array a = new Array();
         a.Append(m);
         return a;
     }
     else if (m is Double) {
         Array a = new Array();
         a.Append(m);
         return a;
     }
     else if (m is String) {
         Array a = new Array();
         a.Append(m);
         return a;
     }
     else if (m is Array)
         return (Array)m;
     else if (m is Object) {
         Array result = new Array();
         foreach (FieldInfo f in m.GetType().GetFields()) {
             // don't use the internal fields __id and __maxId
             if (f.Name != "__id" && f.Name != "__maxId") {
                 String name;
                 if (f.Name.StartsWith("$"))
                     name = new String(f.Name.Substring(1, f.Name.Length - 1));
                 else
                     name = new String(f.Name);
                 Mixed value = (Mixed)f.GetValue(m);
                 result.Append(name, value);
             }
         }
         return result;
     }
     else if (m is Null)
         return new Array();
     else
         return new Array();
 }
예제 #2
0
파일: Convert.cs 프로젝트: emtees/old-code
		public static Array ToArray(object o) {
			Core.DeReference(ref o);
			if (o == null)
				return new Array();
			if (o is bool || o is int || o is double || o is string) {
				Array a = new Array();
				a.Append(o);
				return a;
			}
			if (o is Array)
				return (Array)o;
			Array result = new Array();
			foreach (FieldInfo f in o.GetType().GetFields()) {
				// don't use the internal fields __Id and __MaxId
				if (f.Name != "__Id" && f.Name != "__MaxId") {
					object value = f.GetValue(o);
					result.Append(f.Name, value);
				}
			}
			return result;
		}