Skip to content

Commit 0017251

Browse files
authored
Merge pull request #7 from greymind/support-shadowed-properties
Support shadowed properties
2 parents 8ebb292 + ceb09ec commit 0017251

22 files changed

+13225
-98
lines changed

.gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
packages/
1+
/src/packages
22
.vs/
33
bin/
44
obj/
5+
/src/WebApiTestApplication/Scripts/CompiledTypeScript/
56
*.csproj.user
6-
src/WebApiTestApplication/Scripts/typings/
7-
src/WebApiTestApplication/Scripts/CompiledTypeScript/
7+
*.DotSettings.user
88
*.nupkg

src/WebApiTestApplication/Controllers/TestController.cs

+27-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ public class AnotherClass
6767
public string[] List { get; set; }
6868
}
6969

70+
public class DerivedClassWithShadowedProperty : AnotherClass
71+
{
72+
public new string Number { get; set; }
73+
}
74+
75+
public class DerivedClassWithAnotherShadowedProperty : DerivedClassWithShadowedProperty
76+
{
77+
public new int Number { get; set; }
78+
}
79+
7080
[RoutePrefix("api/Test/{hole}/actions")]
7181
public class TestController : ApiController
7282
{
@@ -83,14 +93,7 @@ public string Get([EncryptedInt] int id, string hole)
8393
{
8494
return $"value {hole} / {id}";
8595
}
86-
87-
//[HttpGet]
88-
//[Route("getty/{id:encryptedInt}")]
89-
//public string Getty(int id, string hole)
90-
//{
91-
// return $"{nameof(Getty)}: value {hole} / {id}";
92-
//}
93-
96+
9497
[HttpGet]
9598
[Route("getSomething/{id}/ha")]
9699
public string GetSomething(string hole, int id, DummyEnum y = DummyEnum.Bye)
@@ -113,6 +116,22 @@ public string Post(string hole, DummyClass value)
113116
return $"thanks for the {valueJson} in the {hole}";
114117
}
115118

119+
[HttpPost]
120+
[Route("derived")]
121+
public string Post(string hole, DerivedClassWithShadowedProperty value)
122+
{
123+
var valueJson = JsonConvert.SerializeObject(value);
124+
return $"thanks for the {valueJson} in the {hole}";
125+
}
126+
127+
[HttpPost]
128+
[Route("derivedAgain")]
129+
public string Post(string hole, DerivedClassWithAnotherShadowedProperty value)
130+
{
131+
var valueJson = JsonConvert.SerializeObject(value);
132+
return $"thanks for the {valueJson} in the {hole}";
133+
}
134+
116135
[HttpPut]
117136
[Route("{id}")]
118137
public string Put(int id, [FromBody]string value, string hole)

src/WebApiTestApplication/Scripts/Angular.ts

+30-28
Original file line numberDiff line numberDiff line change
@@ -25,72 +25,74 @@ class TestController {
2525
megaClass.something = 7;
2626

2727
endpointsService.Test.Get({
28-
hole: "cap"
29-
})
28+
hole: "cap"
29+
})
3030
.call()
3131
.then(responsePrinter);
3232

3333
endpointsService.Test.Get1({
34-
hole: "cap",
35-
id: "777"
36-
})
34+
hole: "cap",
35+
id: "777"
36+
})
3737
.call()
3838
.then(responsePrinter);
3939

4040
endpointsService.Test.GetSomething({
41-
hole: "cap",
42-
id: 7,
43-
y: Enums.DummyEnum.Bye
44-
})
41+
hole: "cap",
42+
id: 7,
43+
y: Enums.DummyEnum.Bye
44+
})
4545
.call()
4646
.then(responsePrinter);
4747

4848
endpointsService.Test.GetSomethingElse({
49-
hole: "cap",
50-
id: 3,
51-
y: dummyClass
52-
})
49+
hole: "cap",
50+
id: 3,
51+
y: dummyClass
52+
})
5353
.call()
5454
.then(responsePrinter);
5555

5656
endpointsService.Test.Post({
57-
hole: "cap"
58-
})
57+
hole: "cap"
58+
})
5959
.call(null)
6060
.then(responsePrinter);
6161

6262
endpointsService.Test.Post({
63-
hole: "cap"
64-
})
63+
hole: "cap"
64+
})
6565
.call(dummyClass)
6666
.then(responsePrinter);
6767

6868
endpointsService.Test.Put({
69-
hole: "cap",
70-
id: 5
71-
})
69+
hole: "cap",
70+
id: 5
71+
})
7272
.call("b")
7373
.then(responsePrinter);
7474

7575
endpointsService.Test.Delete({
76-
hole: "cap",
77-
id: 2
78-
})
76+
hole: "cap",
77+
id: 2
78+
})
7979
.call()
8080
.then(responsePrinter);
8181

8282
endpointsService.Thingy.Get({
83-
id: 1,
84-
x: "blah",
85-
c: megaClass
86-
})
83+
id: 1,
84+
x: "blah",
85+
c: megaClass
86+
})
8787
.call()
8888
.then(responsePrinter);
8989

9090
endpointsService.Thingy.Post()
9191
.call({
9292
something: 7,
93-
number: 1
93+
number: 1,
94+
name: null,
95+
list: null
9496
})
9597
.then(responsePrinter);
9698
}

src/WebApiTestApplication/Scripts/Endpoints/Endpoints.ts

+44-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Endpoints {
1414
}
1515

1616
if (_.isArray(value)) {
17-
var encodedItems = _.map(value, (item) => encodeURIComponent(item.toString()));
18-
parameters.push(`${key}=${encodedItems.join(',')}`);
17+
var encodedItems = _.map(value, (item: any) => encodeURIComponent(item.toString()));
18+
_(encodedItems).each(item => parameters.push(`${key}=${item}`));
1919
}
2020
else {
2121
parameters.push(`${key}=${encodeURIComponent(value.toString())}`);
@@ -188,6 +188,48 @@ namespace Endpoints {
188188
}
189189
}
190190

191+
export interface IPost1 {
192+
hole: string;
193+
}
194+
195+
export interface IPost1WithCall extends IPost1, IEndpoint {
196+
call<TView>(value: Interfaces.IDerivedClassWithShadowedProperty): ng.IPromise<TView>;
197+
}
198+
199+
export class Post1 implements IPost1, IEndpoint {
200+
_verb = 'POST';
201+
hole: string;
202+
203+
constructor(args: IPost1) {
204+
this.hole = args != null ? args.hole : null;
205+
}
206+
207+
toString = (): string => {
208+
return `/api/Test/${this.hole}/actions/derived`;
209+
}
210+
}
211+
212+
export interface IPost2 {
213+
hole: string;
214+
}
215+
216+
export interface IPost2WithCall extends IPost2, IEndpoint {
217+
call<TView>(value: Interfaces.IDerivedClassWithAnotherShadowedProperty): ng.IPromise<TView>;
218+
}
219+
220+
export class Post2 implements IPost2, IEndpoint {
221+
_verb = 'POST';
222+
hole: string;
223+
224+
constructor(args: IPost2) {
225+
this.hole = args != null ? args.hole : null;
226+
}
227+
228+
toString = (): string => {
229+
return `/api/Test/${this.hole}/actions/derivedAgain`;
230+
}
231+
}
232+
191233
export interface IPut {
192234
id: number;
193235
hole: string;

src/WebApiTestApplication/Scripts/Endpoints/Service.ts

+18
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,24 @@ namespace Endpoints {
6363
});
6464
},
6565

66+
Post1: (args: Endpoints.Test.IPost1): Endpoints.Test.IPost1WithCall => {
67+
var endpoint = new Endpoints.Test.Post1(args);
68+
return _.extendOwn(endpoint, {
69+
call<TView>(value: Interfaces.IDerivedClassWithShadowedProperty) {
70+
return AngularEndpointsService.call<TView>(this, value != null ? value : null);
71+
}
72+
});
73+
},
74+
75+
Post2: (args: Endpoints.Test.IPost2): Endpoints.Test.IPost2WithCall => {
76+
var endpoint = new Endpoints.Test.Post2(args);
77+
return _.extendOwn(endpoint, {
78+
call<TView>(value: Interfaces.IDerivedClassWithAnotherShadowedProperty) {
79+
return AngularEndpointsService.call<TView>(this, value != null ? value : null);
80+
}
81+
});
82+
},
83+
6684
Put: (args: Endpoints.Test.IPut): Endpoints.Test.IPutWithCall => {
6785
var endpoint = new Endpoints.Test.Put(args);
6886
return _.extendOwn(endpoint, {

0 commit comments

Comments
 (0)