Skip to content

Commit 10cc8a7

Browse files
committed
refactoring on generated codes
1 parent 5d357e9 commit 10cc8a7

File tree

8 files changed

+152
-389
lines changed

8 files changed

+152
-389
lines changed

DemoCoreWeb.ClientApi/WebApiClientAuto.cs

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

DemoCoreWeb.ClientApiTextJson/WebApiClientTextJsonAuto.cs

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

DemoTextJsonWeb/OAuth2RequestBinderProvider.cs

Lines changed: 0 additions & 222 deletions
This file was deleted.

DemoTextJsonWeb/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#if DEBUG
3131
configure.Conventions.Add(new Fonlow.CodeDom.Web.ApiExplorerVisibilityEnabledConvention());//To make ApiExplorer be visible to WebApiClientGen
3232
#endif
33-
configure.ModelBinderProviders.Insert(0, new OAuth2RequestBinderProvider());
3433
})
3534
.AddJsonOptions(// as of .NET 7/8, could not handle JS/CS test cases getInt2D, postInt2D and PostDictionaryOfPeople, around 14 C# test cases fail.
3635
options =>

Fonlow.Poco2TsCore/AnnotationDeclarationGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Fonlow.Poco2Client
77
{
88
/// <summary>
9-
/// Provide a dictionary to translate an attribute type to CodeAttributeDeclaration
9+
/// Provide a dictionary to translate an attribute object to CodeAttributeDeclaration
1010
/// </summary>
1111
public sealed class AnnotationDeclarationGenerator
1212
{
@@ -127,7 +127,7 @@ public static IDictionary<Type, Func<Attribute, CodeAttributeDeclaration>> Creat
127127
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
128128
}
129129

130-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RegularExpressionAttribute", attributeParams.ToArray());
130+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RegularExpression", attributeParams.ToArray());
131131
}
132132
},
133133
{ typeof(ObsoleteAttribute), a =>
@@ -166,7 +166,7 @@ public static CodeAttributeDeclaration CreateDeclaration(ObsoleteAttribute obj){
166166
attributeParams.Add(new CodeAttributeArgument("UrlFormat", urlFormatExp));
167167
}
168168

169-
return new CodeAttributeDeclaration("System.ObsoleteAttribute", attributeParams.ToArray());
169+
return new CodeAttributeDeclaration("System.Obsolete", attributeParams.ToArray());
170170
}
171171

172172
}

WebApiClientGenCore.Abstract/ClientApiTsFunctionGenAbstract.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,6 @@ void CreateDocComments()
186186

187187
foreach (ParameterDescription paramDesc in Description.ParameterDescriptions)
188188
{
189-
//var tsParameterType = Poco2TsGen.TranslateToClientTypeReference(paramDesc.ParameterDescriptor.ParameterType);
190-
//var parameterComment = Fonlow.DocComment.DocCommentHelper.GetParameterComment(methodComments, paramDesc.Name);
191-
//if (String.IsNullOrEmpty(parameterComment))
192-
//{
193-
// bool paramTypeCommentExists = dotNetTypeCommentDic.TryGetValue(paramDesc.ParameterDescriptor.ParameterType, out string paramTypeComment);
194-
// if (paramTypeCommentExists)
195-
// {
196-
// builder.AppendLine($"@param {{{TypeMapper.MapCodeTypeReferenceToTsText(tsParameterType)}}} {paramDesc.Name} {paramTypeComment}");
197-
// }
198-
//}
199-
//else
200-
//{
201-
// builder.AppendLine($"@param {{{TypeMapper.MapCodeTypeReferenceToTsText(tsParameterType)}}} {paramDesc.Name} {parameterComment}");
202-
//}
203189
string parameterComment = Fonlow.DocComment.DocCommentHelper.GetParameterComment(methodComments, paramDesc.Name);
204190
CreateParamDocComment(builder, paramDesc, parameterComment);
205191
}

WebApiClientGenCore.Abstract/Poco2CsGen.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ CodeTypeDeclaration TypeToCodeTypeDeclaration(Type type, CodeNamespaceEx clientN
324324
bool isRequired = cherryType == CherryType.BigCherry;
325325
if (isRequired)
326326
{
327-
clientProperty.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RequiredAttribute"));
327+
clientProperty.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Required"));
328328
}
329329

330330
if (codeGenOutputsSettings.DataAnnotationsEnabled)
@@ -369,7 +369,7 @@ CodeTypeDeclaration TypeToCodeTypeDeclaration(Type type, CodeNamespaceEx clientN
369369
bool isRequired = cherryType == CherryType.BigCherry;
370370
if (isRequired)
371371
{
372-
clientProperty.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RequiredAttribute"));
372+
clientProperty.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Required"));
373373
}
374374

375375
if (codeGenOutputsSettings.DataAnnotationsEnabled)
@@ -419,7 +419,7 @@ CodeTypeDeclaration TypeToCodeTypeDeclaration(Type type, CodeNamespaceEx clientN
419419

420420
if (codeGenOutputsSettings.DecorateDataModelWithSerializable)
421421
{
422-
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("System.SerializableAttribute"));
422+
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("System.Serializable"));
423423
}
424424
}
425425
else if (type.IsEnum)
@@ -431,7 +431,7 @@ CodeTypeDeclaration TypeToCodeTypeDeclaration(Type type, CodeNamespaceEx clientN
431431
CustomAttributeData newtonJsonConverterAttributeData = type.CustomAttributes.FirstOrDefault(d => d.AttributeType.FullName == "Newtonsoft.Json.JsonConverterAttribute");
432432
if (newtonJsonConverterAttributeData != null)
433433
{
434-
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration(codeGenOutputsSettings.UseSystemTextJson ? "System.Text.Json.Serialization.JsonConverterAttribute" : "Newtonsoft.Json.JsonConverterAttribute", new CodeAttributeArgument(new CodeSnippetExpression(codeGenOutputsSettings.UseSystemTextJson ? "typeof(System.Text.Json.Serialization.JsonStringEnumConverter)" : "typeof(Newtonsoft.Json.Converters.StringEnumConverter)"))));
434+
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration(codeGenOutputsSettings.UseSystemTextJson ? "System.Text.Json.Serialization.JsonConverter" : "Newtonsoft.Json.JsonConverter", new CodeAttributeArgument(new CodeSnippetExpression(codeGenOutputsSettings.UseSystemTextJson ? "typeof(System.Text.Json.Serialization.JsonStringEnumConverter)" : "typeof(Newtonsoft.Json.Converters.StringEnumConverter)"))));
435435
}
436436

437437
CustomAttributeData systemJsonConverterAttributeData = type.CustomAttributes.FirstOrDefault(d => d.AttributeType.FullName == "System.Text.Json.Serialization.JsonConverterAttribute");
@@ -473,7 +473,7 @@ CodeTypeDeclaration TypeToCodeTypeDeclaration(Type type, CodeNamespaceEx clientN
473473

474474
if (codeGenOutputsSettings.DecorateDataModelWithSerializable)
475475
{
476-
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("System.SerializableAttribute"));
476+
typeDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("System.Serializable"));
477477
}
478478
}
479479
else
@@ -690,7 +690,7 @@ CodeMemberField CreateProperty(string name, Type type, string defaultValue)
690690

691691
if (!String.IsNullOrEmpty(defaultValue))
692692
{
693-
result.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DefaultValueAttribute", new CodeAttributeArgument(new CodeSnippetExpression(defaultValue))));
693+
result.CustomAttributes.Add(new CodeAttributeDeclaration("System.ComponentModel.DefaultValue", new CodeAttributeArgument(new CodeSnippetExpression(defaultValue))));
694694
}
695695

696696

@@ -782,7 +782,7 @@ public string TranslateToClientTypeReferenceText(Type type, bool forDocComment)
782782
if (type.FullName == "System.Net.Http.HttpResponseMessage")
783783
return "System.Net.Http.HttpResponseMessage";
784784

785-
if (type.FullName == "System.Object" && (type.Attributes & TypeAttributes.Serializable) == TypeAttributes.Serializable)
785+
if (type.FullName == "System.Object")// && (type.Attributes & TypeAttributes.Serializable) == TypeAttributes.Serializable)
786786
return codeGenOutputsSettings.UseSystemTextJson ? "System.Text.Json.Nodes.JsonObject" : "Newtonsoft.Json.Linq.JObject";
787787
}
788788

WebApiClientGenCore/ClientApiFunctionGen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ CodeMemberMethod CreateApiFunction()
125125
CreateDocComments();
126126
if (codeGenOutputsSettings.MaybeNullAttributeOnMethod && returnTypeDecoratedWithMaybeNullable)
127127
{
128-
clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.MaybeNullAttribute"));
128+
clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.MaybeNull"));
129129
}
130130
else if (codeGenOutputsSettings.NotNullAttributeOnMethod && returnTypeDecoratedWithNotNullable)
131131
{
132-
clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.NotNullAttribute"));
132+
clientMethod.ReturnTypeCustomAttributes.Add(new CodeAttributeDeclaration("System.Diagnostics.CodeAnalysis.NotNull"));
133133
}
134134

135135
System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo;

0 commit comments

Comments
 (0)