|
@@ -11,7 +11,7 @@ namespace FlutterCodeGenerator
|
|
|
|
|
|
public static List<ComplexModelType> TemporaryList { get; set; }
|
|
|
private List<ComplexModelType> _usedComplexModelTypeList;
|
|
|
- private List<Type> _userDefinedGenericTypeList;
|
|
|
+
|
|
|
private List<string> _userDefinedComplexReturnTypeList;
|
|
|
private string _serviceName;
|
|
|
|
|
@@ -22,7 +22,6 @@ namespace FlutterCodeGenerator
|
|
|
MethodMapList = new List<MethodMap>();
|
|
|
var methodsList = type.GetMethods();
|
|
|
_serviceName = type.Name[1..];
|
|
|
- _userDefinedGenericTypeList = new List<Type>();
|
|
|
foreach (var method in methodsList)
|
|
|
{
|
|
|
var methodMap = new MethodMap(method);
|
|
@@ -35,40 +34,114 @@ namespace FlutterCodeGenerator
|
|
|
public string GetServiceModelDartString()
|
|
|
{
|
|
|
var dartString = new StringBuilder();
|
|
|
+ var importServiceList = new List<string>();
|
|
|
foreach (var modelType in _usedComplexModelTypeList)
|
|
|
{
|
|
|
- if (modelType is UserDefinedGenericModelType)
|
|
|
+ if (!CodeGenerator.AlreadyGeneratedList.Any(x => x.Key.ParameterType.Name == modelType.ParameterType.Name))
|
|
|
{
|
|
|
- var genericType = modelType.ParameterType.GetGenericTypeDefinition();
|
|
|
- if (!_userDefinedGenericTypeList.Contains(genericType))
|
|
|
- {
|
|
|
- dartString.AppendLine(modelType.GetDartString());
|
|
|
- _userDefinedGenericTypeList.Add(genericType);
|
|
|
- }
|
|
|
+ CodeGenerator.AlreadyGeneratedList.Add(modelType, _serviceName);
|
|
|
+ dartString.AppendLine(modelType.GetDartString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- dartString.AppendLine(modelType.GetDartString());
|
|
|
+ var importService = CodeGenerator.AlreadyGeneratedList.FirstOrDefault(x => x.Key.ParameterType.Name == modelType.ParameterType.Name).Value;
|
|
|
+ if (importService == null)
|
|
|
+ {
|
|
|
+ throw new Exception("Import Service is null");
|
|
|
+ }
|
|
|
+ if (importService != _serviceName && !importServiceList.Contains(importService))
|
|
|
+ {
|
|
|
+ importServiceList.Add(importService);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
if (string.IsNullOrWhiteSpace(dartString.ToString()))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
var serviceModelDartString = new StringBuilder();
|
|
|
- if (dartString.ToString().Contains("FJsonConvert"))
|
|
|
+ foreach (var importService in importServiceList)
|
|
|
+ {
|
|
|
+ serviceModelDartString.AppendLine($"import '{LetterConverterHelper.FirstCharToLower(importService[0..^7]) }.m.dart';");
|
|
|
+ }
|
|
|
+ if (importServiceList.Count > 0)
|
|
|
+ {
|
|
|
+ serviceModelDartString.AppendLine();
|
|
|
+ }
|
|
|
+
|
|
|
+ var dartStringInfo = dartString.ToString();
|
|
|
+ if (dartStringInfo.Contains("JsonRpcUtils"))
|
|
|
+ {
|
|
|
+ serviceModelDartString.AppendLine(CodeGenerator.StringUtils);
|
|
|
+ serviceModelDartString.AppendLine();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dartStringInfo.Contains("FJsonConvert"))
|
|
|
{
|
|
|
serviceModelDartString.AppendLine(CodeGenerator.StringJsonConvert);
|
|
|
serviceModelDartString.AppendLine();
|
|
|
}
|
|
|
- serviceModelDartString.AppendLine(dartString.ToString());
|
|
|
+ serviceModelDartString.AppendLine(dartStringInfo);
|
|
|
return serviceModelDartString.ToString();
|
|
|
}
|
|
|
|
|
|
public string GetServiceDartString()
|
|
|
{
|
|
|
var serviceDartString = new StringBuilder();
|
|
|
+ var importServiceList = new List<string>();
|
|
|
+ foreach (var methodMap in MethodMapList)
|
|
|
+ {
|
|
|
+ string importService = null;
|
|
|
+ foreach (var modelType in methodMap.ParameterModeTypes)
|
|
|
+ {
|
|
|
+ if (modelType is ComplexModelType)
|
|
|
+ {
|
|
|
+ importService = CodeGenerator.AlreadyGeneratedList.FirstOrDefault(x => x.Key.ParameterType.Name == modelType.ParameterType.Name).Value;
|
|
|
+ if (importService == null)
|
|
|
+ {
|
|
|
+ throw new Exception("Import Service is null");
|
|
|
+ }
|
|
|
+ if (importService != _serviceName && !importServiceList.Contains(importService))
|
|
|
+ {
|
|
|
+ importServiceList.Add(importService);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var complexReturnTypeNameList = GetUserDefinedComplexReturnTypeList();
|
|
|
+ foreach (var complexReturnTypeName in complexReturnTypeNameList)
|
|
|
+ {
|
|
|
+ string importService;
|
|
|
+ if (complexReturnTypeName.Contains("<"))
|
|
|
+ {
|
|
|
+ var returnTypeName = complexReturnTypeName.Substring(0, complexReturnTypeName.IndexOf("<"));
|
|
|
+ importService = CodeGenerator.AlreadyGeneratedList.FirstOrDefault(x => x.Key.ParameterType.Name[0..^2] == returnTypeName).Value;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ importService = CodeGenerator.AlreadyGeneratedList.FirstOrDefault(x => x.Key.ParameterType.Name == complexReturnTypeName).Value;
|
|
|
+ }
|
|
|
+ if (importService == null)
|
|
|
+ {
|
|
|
+ throw new Exception("Import Service is null");
|
|
|
+ }
|
|
|
+ if (importService != _serviceName && !importServiceList.Contains(importService))
|
|
|
+ {
|
|
|
+ importServiceList.Add(importService);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach (var importService in importServiceList)
|
|
|
+ {
|
|
|
+ serviceDartString.AppendLine($"import '{LetterConverterHelper.FirstCharToLower(importService[0..^7]) }.m.dart';");
|
|
|
+ }
|
|
|
+ if (importServiceList.Count > 0)
|
|
|
+ {
|
|
|
+ serviceDartString.AppendLine();
|
|
|
+ }
|
|
|
+
|
|
|
+ serviceDartString.AppendLine();
|
|
|
serviceDartString.AppendLine($"class {_serviceName} extends JsonRpcClientBase {{");
|
|
|
serviceDartString.AppendLine($"\t{_serviceName}(");
|
|
|
serviceDartString.AppendLine("\t\tString host, {");
|
|
@@ -81,7 +154,6 @@ namespace FlutterCodeGenerator
|
|
|
serviceDartString.AppendLine("\t\t\t\t\t\theaders: headers,");
|
|
|
serviceDartString.AppendLine("\t\t\t\t\t\ttimeout: timeout,");
|
|
|
|
|
|
- var complexReturnTypeNameList = GetUserDefinedComplexReturnTypeList();
|
|
|
if (complexReturnTypeNameList.Count() == 0)
|
|
|
{
|
|
|
serviceDartString.AppendLine("\t\t\t\t);");
|