Exemple #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value != null)
            {
                bool           isControls = value is MapControls;
                PropertyInfo[] properties = value.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                StringBuilder  sb         = new StringBuilder();

                foreach (PropertyInfo property in properties)
                {
                    ConfigOptionAttribute attr = ClientConfig.GetClientConfigAttribute(property);

                    if (attr != null && property.PropertyType == typeof(bool))
                    {
                        object prValue      = property.GetValue(value, null);
                        object defaultValue = ReflectionUtils.GetDefaultValue(property);
                        if ((bool)prValue)
                        {
                            if (!isControls)
                            {
                                if (!(bool)defaultValue)
                                {
                                    sb.Append(string.Concat("'enable", property.Name, "',"));
                                }
                            }
                            else
                            {
                                sb.Append(string.Concat("'", property.Name, "',"));
                            }
                        }
                        else
                        {
                            if (!isControls)
                            {
                                if ((bool)defaultValue)
                                {
                                    sb.Append(string.Concat("'disable", property.Name, "',"));
                                }
                            }
                        }
                    }
                }

                if (sb.Length > 0)
                {
                    sb.Remove(sb.Length - 1, 1);
                    writer.WriteStartArray();
                    writer.WriteRaw(sb.ToString());
                    writer.WriteEndArray();
                    return;
                }
            }
            writer.WriteStartArray();
            writer.WriteEndArray();
        }