Browse Source

修复当属性为小写字母时,生成的dart为大写的问题。

Felix 2 years ago
parent
commit
11d1eac5f4
2 changed files with 15 additions and 1 deletions
  1. 1 1
      CodeGenerator.cs
  2. 14 0
      LetterConverterHelper.cs

+ 1 - 1
CodeGenerator.cs

@@ -119,7 +119,7 @@ namespace FlutterCodeGenerator
             dartString.AppendLine(tempStringArray[0]);
             foreach (var serviceMap in _serviceMapDictionary)
             {
-                var serviceName = LetterConverterHelper.FirstCharToUpper(serviceMap.Key);
+                var serviceName = LetterConverterHelper.FirstCharToUpper_2(serviceMap.Key);
                 var actionName = serviceMap.Key[0..^7];
                 dartString.AppendLine($"\t{serviceName} get {actionName} =>");
                 dartString.AppendLine($"\tfindService(() => new {serviceName}(currentHostAddress));");

+ 14 - 0
LetterConverterHelper.cs

@@ -34,5 +34,19 @@ namespace FlutterCodeGenerator
             var str = input.First().ToString().ToUpper() + input.Substring(1);
             return str;
         }
+
+        /// <summary>
+        /// 首字母大写
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public static string FirstCharToUpper_2(string input)
+        {
+            if (string.IsNullOrEmpty(input))
+                return input;
+            var firstChar = input[0];
+            var str = input.First().ToString().ToUpper() + input.Substring(1);
+            return str;
+        }
     }
 }