Exemple #1
0
        void SerializeObject(SLJsonWriter writer)
        {
            writer.BeginObject();

            foreach (string n in Names)
            {
                writer.BeginField(n);
                this[n].Serialize(writer);
            }

            writer.EndObject();
        }
Exemple #2
0
        void SerializeObject(SLJsonWriter writer, object instance)
        {
            if (instance == null)
            {
                writer.WriteValueNull();
            }
            else
            {
                writer.BeginObject();

                Type t = instance.GetType();

                foreach (FieldInfo fi in t.GetRuntimeFields())
                {
                    if (fi.IsPublic)
                    {
                        foreach (SLJsonMemberAttribute attr in fi.GetCustomAttributes(typeof(SLJsonMemberAttribute), false))
                        {
                            SerializeProperty(writer, attr, fi.FieldType, fi.GetValue(instance));
                        }
                    }
                }

                foreach (PropertyInfo pi in t.GetRuntimeProperties())
                {
                    if (pi.CanRead && pi.CanWrite)
                    {
                        MethodInfo mi1 = pi.GetGetMethod();
                        if (mi1 != null && mi1.IsPublic)
                        {
                            MethodInfo mi2 = pi.GetSetMethod();
                            if (mi2 != null && mi2.IsPublic)
                            {
                                foreach (SLJsonMemberAttribute attr in pi.GetCustomAttributes(typeof(SLJsonMemberAttribute), false))
                                {
                                    SerializeProperty(writer, attr, pi.PropertyType, pi.GetValue(instance, null));
                                }
                            }
                        }
                    }
                }

                writer.EndObject();
            }
        }