ManagedFusion.Serialization.Serializer.SerializeObject C# (CSharp) Méthode

SerializeObject() private méthode

Serializes the object.
private SerializeObject ( object obj, int level, int levelLimit ) : object>.IDictionary
obj object The obj.
level int
levelLimit int
Résultat object>.IDictionary
        private IDictionary<string, object> SerializeObject(object obj, int level, int levelLimit)
        {
            IDictionary<string, object> values = new Dictionary<string, object>();

            if (level >= levelLimit)
                return values;
            else
                level++;

            Type type = obj.GetType();
            bool anonymousType = type.Name.IndexOf("__AnonymousType") >= 0;

            foreach (FieldInfo info in type.GetFields(BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                try
                {
                    if (FollowFrameworkIgnoreAttributes && (info.IsDefined(typeof(XmlIgnoreAttribute), true) || info.IsDefined(typeof(SoapIgnoreAttribute), true)))
                        continue;

                    if ((SerializePublicMembers && info.IsPublic) || info.IsDefined(typeof(SerializablePropertyAttribute), true))
                        values.Add(SerializeName(info), SerializeValue(info.GetValue(obj), level, levelLimit));
                }
                catch (Exception exc)
                {
                    throw new ApplicationException("Error encountered on field " + SerializeName(info), exc);
                }
            }

            foreach (PropertyInfo info2 in type.GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                try
                {
                    MethodInfo getMethod = info2.GetGetMethod(true);

                    if (FollowFrameworkIgnoreAttributes && (info2.IsDefined(typeof(XmlIgnoreAttribute), true) || info2.IsDefined(typeof(SoapIgnoreAttribute), true)))
                        continue;

                    if ((getMethod != null) && (getMethod.GetParameters().Length <= 0))
                        if (anonymousType || (SerializePublicMembers && getMethod.IsPublic) || info2.IsDefined(typeof(SerializablePropertyAttribute), true))
                            values.Add(SerializeName(info2), SerializeValue(getMethod.Invoke(obj, null), level, levelLimit));
                }
                catch (Exception exc)
                {
                    throw new ApplicationException("Error encountered on property " + SerializeName(info2), exc);
                }
            }

            return values;
        }