public int expand(object o, OnChildNode listener)
        {
            if (o == null)
            {
                return(0);
            }
            if (o.GetType() == (typeof(DateTime)))
            {
                Int64 ewokTime = NodeExpanderConstants.extractEpochTimeMillis((DateTime)o);
                listener(o, NodeExpanderConstants.unixEpochTimeMillisFieldName, ewokTime);
                return(1);
            }

            Type theclass = o.GetType();

            FieldInfo[] fis = theclass.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Default);
            foreach (FieldInfo fi in fis)
            {
                // ignore property backing fields!
                if (isPropertyAutoField(fi))
                {
                    continue;
                }
                Object value = fi.GetValue(o);
                if (fi.FieldType.IsEnum)
                {
                    value = Enum.GetName(fi.FieldType, value);
                }

                listener(o, fi.Name, value);
            }
            return(fis.Length);
        }
Esempio n. 2
0
        public int expand(object o, OnChildNode onChildNode)
        {
            //treat dates differently !
            if (o.GetType() == (typeof(DateTime)))
            {
                if (o.GetType() == (typeof(DateTime)))
                {
                    Int64 ewokTime = NodeExpanderConstants.extractEpochTimeMillis((DateTime)o);
                    onChildNode(o, NodeExpanderConstants.unixEpochTimeMillisPropertyName, ewokTime);
                    return(1);
                }
            }
            PropertyInfo [] pis          = o.GetType().GetProperties();
            int             setAbleCount = 0;

            foreach (PropertyInfo pi in pis)
            {
                if (ExcludeReadOnlyProperties && pi.GetSetMethod() == null)
                {
                    continue;
                }
                Object value = null;
                try
                {
                    value = pi.GetValue(o);
                    if (pi.PropertyType.IsEnum)
                    {
                        value = Enum.GetName(pi.PropertyType, value);
                    }
                    setAbleCount++;
                }
                catch (Exception ex)
                {
                    Exception exx = new Exception("failed to get value for property " + pi.Name + " declared in " + pi.DeclaringType, ex);
                    throw exx;
                }

                String name = Char.ToLower(pi.Name[0]) + pi.Name.Substring(1);
                name = pi.Name;
                onChildNode(o, name, value);
            }
            return(setAbleCount);
        }