Skip to content

Commit bff1ebf

Browse files
committed
ObsoleteAttribute on C# property OK
1 parent 779d0d6 commit bff1ebf

File tree

9 files changed

+173
-116
lines changed

9 files changed

+173
-116
lines changed

DemoCoreWeb.ClientApi/WebApiClientAuto.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9659,6 +9659,7 @@ public class Company : DemoWebApi.DemoData.Client.BizEntity
96599659
[System.Runtime.Serialization.DataMember()]
96609660
public string BusinessNumberType { get; set; }
96619661

9662+
[System.ObsoleteAttribute("")]
96629663
[System.Runtime.Serialization.DataMember()]
96639664
public string[][] TextMatrix { get; set; }
96649665

@@ -9826,6 +9827,14 @@ public class MimsPackage : object
98269827

98279828
[System.Runtime.Serialization.DataMember()]
98289829
public string Tag { get; set; }
9830+
9831+
[System.ObsoleteAttribute("Just for testing", true)]
9832+
[System.Runtime.Serialization.DataMember()]
9833+
public string TagForTest { get; set; }
9834+
9835+
[System.ObsoleteAttribute("Just for testing", DiagnosticId="someId", UrlFormat="WhateverFormat")]
9836+
[System.Runtime.Serialization.DataMember()]
9837+
public string TagForTest2 { get; set; }
98299838
}
98309839

98319840
[System.Runtime.Serialization.DataContract(Namespace="http://fonlowdemo.com/2020/09")]

DemoCoreWeb/Scripts/ClientApi/WebApiCoreJQClientAuto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,8 @@ namespace DemoWebApi_DemoData_Client {
17621762
optionalInt?: number | null;
17631763
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
17641764
tag?: string | null;
1765+
tagForTest?: string | null;
1766+
tagForTest2?: string | null;
17651767
}
17661768

17671769
export interface MimsResult<T> {

DemoWebApi.DemoDataCore/Entities.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ public class Company : BizEntity
277277
[DataMember]
278278
public string BusinessNumberType { get; set; }
279279

280+
[Obsolete]
280281
[DataMember]
281282
public string[][] TextMatrix
282283
{ get; set; }
@@ -328,6 +329,14 @@ public class MimsPackage
328329
[DataMember]
329330
public string Tag { get; set; }
330331

332+
[Obsolete("Just for testing", true)]
333+
[DataMember]
334+
public string TagForTest { get; set; }
335+
336+
[Obsolete("Just for testing", DiagnosticId ="someId", UrlFormat ="WhateverFormat")]
337+
[DataMember]
338+
public string TagForTest2 { get; set; }
339+
331340
[DataMember]
332341
[Range(10, 100, ErrorMessage = "KK has to be between 10 and 100.")]
333342
[System.ComponentModel.DefaultValue(20)]

Fonlow.Poco2TsCore/AnnotationDeclarationGenerator.cs

Lines changed: 139 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -5,132 +5,155 @@
55

66
namespace Fonlow.Poco2Client
77
{
8-
/// <summary>
9-
/// Provide a dictionary to translate an attribute type to CodeAttributeDeclaration
10-
/// </summary>
11-
public sealed class AnnotationDeclarationGenerator
12-
{
13-
public static IDictionary<Type, Func<Attribute, CodeAttributeDeclaration>> Create()
14-
{
15-
return declaratinDic;
16-
}
8+
/// <summary>
9+
/// Provide a dictionary to translate an attribute type to CodeAttributeDeclaration
10+
/// </summary>
11+
public sealed class AnnotationDeclarationGenerator
12+
{
13+
public static IDictionary<Type, Func<Attribute, CodeAttributeDeclaration>> Create()
14+
{
15+
return declaratinDic;
16+
}
1717

18-
static readonly IDictionary<Type, Func<Attribute, CodeAttributeDeclaration>> declaratinDic = new Dictionary<Type, Func<Attribute, CodeAttributeDeclaration>>
19-
{
20-
{ typeof(RequiredAttribute), a => new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Required") },
21-
{ typeof(RangeAttribute), a =>
22-
{
23-
RangeAttribute obj = a as RangeAttribute;
24-
CodeSnippetExpression operandType = new CodeSnippetExpression($"typeof({obj.OperandType.FullName})");
25-
CodeSnippetExpression min = new CodeSnippetExpression($"\"{obj.Minimum}\"");
26-
CodeSnippetExpression max = new CodeSnippetExpression($"\"{obj.Maximum}\"");
18+
static readonly IDictionary<Type, Func<Attribute, CodeAttributeDeclaration>> declaratinDic = new Dictionary<Type, Func<Attribute, CodeAttributeDeclaration>>
19+
{
20+
{ typeof(RequiredAttribute), a => new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Required") },
21+
{ typeof(RangeAttribute), a =>
22+
{
23+
RangeAttribute obj = a as RangeAttribute;
24+
CodeSnippetExpression operandType = new CodeSnippetExpression($"typeof({obj.OperandType.FullName})");
25+
CodeSnippetExpression min = new CodeSnippetExpression($"\"{obj.Minimum}\"");
26+
CodeSnippetExpression max = new CodeSnippetExpression($"\"{obj.Maximum}\"");
2727
//var isNumber = obj.GetType()== typeof(int) || obj.GetType()==typeof(double);
2828
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(operandType),
29-
new CodeAttributeArgument(min),
30-
new CodeAttributeArgument(max) };
31-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
32-
{
33-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
34-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
35-
}
29+
new CodeAttributeArgument(min),
30+
new CodeAttributeArgument(max) };
31+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
32+
{
33+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
34+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
35+
}
3636

37-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Range", attributeParams.ToArray());
38-
}
39-
},
40-
{ typeof(MaxLengthAttribute), a =>
41-
{
42-
MaxLengthAttribute obj= a as MaxLengthAttribute;
43-
CodeSnippetExpression len = new CodeSnippetExpression(obj.Length.ToString());
44-
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(len) };
45-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
46-
{
47-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
48-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
49-
}
37+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Range", attributeParams.ToArray());
38+
}
39+
},
40+
{ typeof(MaxLengthAttribute), a =>
41+
{
42+
MaxLengthAttribute obj= a as MaxLengthAttribute;
43+
CodeSnippetExpression len = new CodeSnippetExpression(obj.Length.ToString());
44+
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(len) };
45+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
46+
{
47+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
48+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
49+
}
5050

51-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.MaxLength", attributeParams.ToArray());
52-
}
53-
},
54-
{ typeof(MinLengthAttribute), a =>
55-
{
56-
MinLengthAttribute obj= a as MinLengthAttribute;
57-
CodeSnippetExpression len = new CodeSnippetExpression(obj.Length.ToString());
58-
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(len) };
59-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
60-
{
61-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
62-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
63-
}
51+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.MaxLength", attributeParams.ToArray());
52+
}
53+
},
54+
{ typeof(MinLengthAttribute), a =>
55+
{
56+
MinLengthAttribute obj= a as MinLengthAttribute;
57+
CodeSnippetExpression len = new CodeSnippetExpression(obj.Length.ToString());
58+
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(len) };
59+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
60+
{
61+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
62+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
63+
}
6464

65-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.MinLength", attributeParams.ToArray());
66-
}
67-
},
68-
{ typeof(LengthAttribute), a =>
69-
{
70-
LengthAttribute obj= a as LengthAttribute;
71-
CodeSnippetExpression min = new CodeSnippetExpression(obj.MinimumLength.ToString());
72-
CodeSnippetExpression max = new CodeSnippetExpression(obj.MaximumLength.ToString());
73-
List<CodeAttributeArgument> attributeParams = new()
74-
{
75-
new CodeAttributeArgument(min),
76-
new CodeAttributeArgument(max)
77-
};
65+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.MinLength", attributeParams.ToArray());
66+
}
67+
},
68+
{ typeof(LengthAttribute), a =>
69+
{
70+
LengthAttribute obj= a as LengthAttribute;
71+
CodeSnippetExpression min = new CodeSnippetExpression(obj.MinimumLength.ToString());
72+
CodeSnippetExpression max = new CodeSnippetExpression(obj.MaximumLength.ToString());
73+
List<CodeAttributeArgument> attributeParams = new()
74+
{
75+
new CodeAttributeArgument(min),
76+
new CodeAttributeArgument(max)
77+
};
7878

79-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
80-
{
81-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
82-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
83-
}
79+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
80+
{
81+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
82+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
83+
}
8484

85-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Length", attributeParams.ToArray());
86-
}
87-
},
88-
{ typeof(StringLengthAttribute), a =>
89-
{
90-
StringLengthAttribute obj= a as StringLengthAttribute;
91-
CodeSnippetExpression max = new CodeSnippetExpression(obj.MaximumLength.ToString());
92-
CodeSnippetExpression min = new CodeSnippetExpression(obj.MinimumLength.ToString());
93-
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(max),
94-
new CodeAttributeArgument("MinimumLength", min) };
95-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
96-
{
97-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
98-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
99-
}
85+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.Length", attributeParams.ToArray());
86+
}
87+
},
88+
{ typeof(StringLengthAttribute), a =>
89+
{
90+
StringLengthAttribute obj= a as StringLengthAttribute;
91+
CodeSnippetExpression max = new CodeSnippetExpression(obj.MaximumLength.ToString());
92+
CodeSnippetExpression min = new CodeSnippetExpression(obj.MinimumLength.ToString());
93+
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(max),
94+
new CodeAttributeArgument("MinimumLength", min) };
95+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
96+
{
97+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
98+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
99+
}
100100

101-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.StringLength", attributeParams.ToArray());
102-
}
103-
},
104-
{ typeof(DataTypeAttribute), a =>
105-
{
106-
DataTypeAttribute obj= a as DataTypeAttribute;
107-
CodeSnippetExpression dataType = new CodeSnippetExpression("System.ComponentModel.DataAnnotations.DataType." + obj.DataType.ToString());
108-
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(dataType) };
109-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
110-
{
111-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
112-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
113-
}
101+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.StringLength", attributeParams.ToArray());
102+
}
103+
},
104+
{ typeof(DataTypeAttribute), a =>
105+
{
106+
DataTypeAttribute obj= a as DataTypeAttribute;
107+
CodeSnippetExpression dataType = new CodeSnippetExpression("System.ComponentModel.DataAnnotations.DataType." + obj.DataType.ToString());
108+
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(dataType) };
109+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
110+
{
111+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
112+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
113+
}
114114

115-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.DataType", attributeParams.ToArray());
116-
}
117-
},
118-
{ typeof(RegularExpressionAttribute), a =>
119-
{
120-
RegularExpressionAttribute obj= a as RegularExpressionAttribute;
121-
string ps = $"@\"{obj.Pattern}\"";
122-
CodeSnippetExpression p = new CodeSnippetExpression(ps);
123-
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(p) };
124-
if (!String.IsNullOrEmpty(obj.ErrorMessage))
125-
{
126-
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
127-
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
128-
}
115+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.DataType", attributeParams.ToArray());
116+
}
117+
},
118+
{ typeof(RegularExpressionAttribute), a =>
119+
{
120+
RegularExpressionAttribute obj= a as RegularExpressionAttribute;
121+
string ps = $"@\"{obj.Pattern}\"";
122+
CodeSnippetExpression p = new CodeSnippetExpression(ps);
123+
List<CodeAttributeArgument> attributeParams = new() { new CodeAttributeArgument(p) };
124+
if (!String.IsNullOrEmpty(obj.ErrorMessage))
125+
{
126+
CodeSnippetExpression error= new CodeSnippetExpression($"\"{obj.ErrorMessage}\"");
127+
attributeParams.Add(new CodeAttributeArgument("ErrorMessage", error));
128+
}
129129

130-
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RegularExpressionAttribute", attributeParams.ToArray());
131-
}
132-
},
133-
};
130+
return new CodeAttributeDeclaration("System.ComponentModel.DataAnnotations.RegularExpressionAttribute", attributeParams.ToArray());
131+
}
132+
},
133+
{ typeof(ObsoleteAttribute), a =>
134+
{
135+
ObsoleteAttribute obj= a as ObsoleteAttribute;
136+
CodeSnippetExpression messageExp = new CodeSnippetExpression($"\"{obj.Message}\"");
137+
CodeSnippetExpression errorExp= new CodeSnippetExpression(obj.IsError?"true":"false");
138+
List<CodeAttributeArgument> attributeParams = obj.IsError ? new() { new CodeAttributeArgument(messageExp), new CodeAttributeArgument(errorExp) }
139+
: new() { new CodeAttributeArgument(messageExp)};
140+
if (!String.IsNullOrEmpty(obj.DiagnosticId))
141+
{
142+
CodeSnippetExpression diagnosticIdExp= new CodeSnippetExpression($"\"{obj.DiagnosticId}\"");
143+
attributeParams.Add(new CodeAttributeArgument("DiagnosticId", diagnosticIdExp));
144+
}
134145

135-
}
146+
if (!String.IsNullOrEmpty(obj.UrlFormat))
147+
{
148+
CodeSnippetExpression urlFormatExp= new CodeSnippetExpression($"\"{obj.UrlFormat}\"");
149+
attributeParams.Add(new CodeAttributeArgument("UrlFormat", urlFormatExp));
150+
}
151+
152+
return new CodeAttributeDeclaration("System.ObsoleteAttribute", attributeParams.ToArray());
153+
}
154+
},
155+
156+
};
157+
158+
}
136159
}

HeroesDemo/src/clientapi/WebApiCoreNG2FormGroupClientAuto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,8 @@ export namespace DemoWebApi_DemoData_Client {
20982098
optionalInt?: number | null;
20992099
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
21002100
tag?: string | null;
2101+
tagForTest?: string | null;
2102+
tagForTest2?: string | null;
21012103
}
21022104
export interface MimsPackageFormProperties {
21032105

@@ -2117,6 +2119,8 @@ export namespace DemoWebApi_DemoData_Client {
21172119
optionalInt: FormControl<number | null | undefined>,
21182120
result: FormControl<DemoWebApi_DemoData_Client.MimsResult<number> | null | undefined>,
21192121
tag: FormControl<string | null | undefined>,
2122+
tagForTest: FormControl<string | null | undefined>,
2123+
tagForTest2: FormControl<string | null | undefined>,
21202124
}
21212125
export function CreateMimsPackageFormGroup() {
21222126
return new FormGroup<MimsPackageFormProperties>({
@@ -2126,6 +2130,8 @@ export namespace DemoWebApi_DemoData_Client {
21262130
optionalInt: new FormControl<number | null | undefined>(undefined),
21272131
result: new FormControl<DemoWebApi_DemoData_Client.MimsResult<number> | null | undefined>(undefined),
21282132
tag: new FormControl<string | null | undefined>(undefined),
2133+
tagForTest: new FormControl<string | null | undefined>(undefined),
2134+
tagForTest2: new FormControl<string | null | undefined>(undefined),
21292135
});
21302136

21312137
}

HeroesDemo/src/clientapi/WebApiCoreNg2ClientAuto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,8 @@ export namespace DemoWebApi_DemoData_Client {
17721772
optionalInt?: number | null;
17731773
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
17741774
tag?: string | null;
1775+
tagForTest?: string | null;
1776+
tagForTest2?: string | null;
17751777
}
17761778

17771779
export interface MimsResult<T> {

aurelia/src/clientapi/WebApiCoreAureliaClientAuto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,8 @@ export namespace DemoWebApi_DemoData_Client {
17711771
optionalInt?: number | null;
17721772
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
17731773
tag?: string | null;
1774+
tagForTest?: string | null;
1775+
tagForTest2?: string | null;
17741776
}
17751777

17761778
export interface MimsResult<T> {

axios/src/clientapi/WebApiCoreAxiosClientAuto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,8 @@ export namespace DemoWebApi_DemoData_Client {
17621762
optionalInt?: number | null;
17631763
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
17641764
tag?: string | null;
1765+
tagForTest?: string | null;
1766+
tagForTest2?: string | null;
17651767
}
17661768

17671769
export interface MimsResult<T> {

fetchapi/src/clientapi/WebApiCoreFetchClientAuto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,6 +1760,8 @@ export namespace DemoWebApi_DemoData_Client {
17601760
optionalInt?: number | null;
17611761
result?: DemoWebApi_DemoData_Client.MimsResult<number>;
17621762
tag?: string | null;
1763+
tagForTest?: string | null;
1764+
tagForTest2?: string | null;
17631765
}
17641766

17651767
export interface MimsResult<T> {

0 commit comments

Comments
 (0)