コード例 #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Enum e = (Enum)value;

            string enumName = e.ToString("G");

            if (char.IsNumber(enumName[0]) ||
                enumName[0] == '-')
            {
                // enum value has no name so write number
                writer.WriteValue(value);
            }
            else
            {
                string finalName = SnakeCasePropertyResolver.ToSnakeCase(enumName);

                _stringEnumConverter.WriteJson(writer, finalName, serializer);
            }
        }
コード例 #2
0
        public string SerializeEnum(object obj, Type type)
        {
            string enumValue = Enum.GetName(type, obj);

            return(SnakeCasePropertyResolver.ToSnakeCase(enumValue));
        }
 protected override string ResolvePropertyName(string propertyName)
 {
     return(SnakeCasePropertyResolver.ToSnakeCase(propertyName));
 }