Ejemplo n.º 1
0
 /// <summary>
 /// 将 SnakeCaseNaming 转换为 snake_case_naming 格式
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static string SnakeCaseNaming(this string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return(string.Empty);
     }
     return(snakeCaseNaming.GetPropertyName(name, false));
 }
Ejemplo n.º 2
0
        protected virtual string ResolvePropertyName([NotNull] string name, bool hasSpecifiedName)
        {
            switch (PropertyNameStrategy)
            {
            case NamingStrategyType.CamelCase:
                return(__camelCaseNaming.GetPropertyName(name, hasSpecifiedName));

            case NamingStrategyType.SnakeCase:
                return(__snakeCaseNaming.GetPropertyName(name, hasSpecifiedName));

            default:
                return(__defaultNaming.GetPropertyName(name, hasSpecifiedName));
            }
        }
Ejemplo n.º 3
0
        public DtoTransformer(CryptoProvider cryptoProvider, HashUtils hashUtils, bool hashSearchKeys = true,
            Func<SecretsData> secretKeyAccessor = null)
        {
            _cryptoProvider = cryptoProvider;
            _hashUtils = hashUtils;
            _hashSearchKeys = hashSearchKeys;
            SecretKeyAccessor = secretKeyAccessor;
            var nameTransformer = new SnakeCaseNamingStrategy(true, true);
            foreach (var field in Enum.GetValues(typeof(SortField)).Cast<SortField>())
            {
                _enumMapping[field] = nameTransformer.GetPropertyName(field.ToString(), true);
            }

            foreach (var field in Enum.GetValues(typeof(StringField)).Cast<StringField>())
            {
                _enumMapping[field] = nameTransformer.GetPropertyName(field.ToString(), true);
            }

            foreach (var field in Enum.GetValues(typeof(NumberField)).Cast<NumberField>())
            {
                _enumMapping[field] = nameTransformer.GetPropertyName(field.ToString(), true);
            }
        }
Ejemplo n.º 4
0
        public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
        {
            foreach (var path in swaggerDoc.Paths.ToArray())
            {
                var apiDescription = context.ApiDescriptions.First(ad => "/" + ad.RelativePath == path.Key);
                var newKey         = path.Key;
                foreach (var parameterDescription in apiDescription.ParameterDescriptions.Where(pd =>
                                                                                                pd.Source == BindingSource.Path))
                {
                    newKey = newKey.Replace(
                        "{" + parameterDescription.Name + "}",
                        "{" + _namingStrategy.GetPropertyName(parameterDescription.Name, false) + "}");
                }

                swaggerDoc.Paths.Remove(path.Key);
                swaggerDoc.Paths.Add(newKey, path.Value);
            }
        }
Ejemplo n.º 5
0
 public override string ConvertName(string name)
 {
     return(_newtonsoftSnakeCaseNamingStrategy.GetPropertyName(name, false));
 }
Ejemplo n.º 6
0
 public static string ToSnakeCase(this string s)
 {
     return(_snakeCaseNamingStrategy.GetPropertyName(s, false));
 }
 public override string ConvertName(string name)
 {
     /* A conversion to snake case implementation goes here. */
     return(_newtonsoftSnakeCaseNamingStrategy.GetPropertyName(name, false));
 }
 public override bool ContainsPrefix(string prefix)
 {
     return(base.ContainsPrefix(namingStrategy.GetPropertyName(prefix, false)));
 }
Ejemplo n.º 9
0
 static string ToSnakeCase(string str) =>
 SnakeCaseNamingStrategy.GetPropertyName(str, false);
 public void Apply(OpenApiParameter parameter, ParameterFilterContext context)
 {
     parameter.Name = _namingStrategy.GetPropertyName(parameter.Name, false);
 }