Skip to content

Commit 31ee751

Browse files
author
Caitlin Bales (MSFT)
committed
Add extra methods to EntityRequestBuilders
Prevents developer from having to manually overwrite: - DriveItemRequestBuilder - IDriveItemReqestBuilder - ThumbnailSetRequestBuilder - IThumbnailSetRequestBuilder
1 parent 76df77a commit 31ee751

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

Templates/Android/BaseModel.template.tt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<#@ template debug="true" hostspecific="true" language="C#" #>
33
<#@ output extension="\\" #>
44
<#
5+
56
CustomT4Host host = (CustomT4Host) Host;
67
var model = host.CurrentModel;
78
CodeWriterAndroid writer = (CodeWriterAndroid) host.CodeWriter;
@@ -799,4 +800,12 @@ public {1} {2}{3}{4} {{";
799800
return
800801
@"// **NOTE** This file was generated by a tool and any changes will be overwritten.";
801802
}
803+
804+
public string AddCustomCode(string className) {
805+
CustomMethods customMethods = new CustomMethods();
806+
var type = customMethods.GetType();
807+
var property = type.GetFields().Where(x => x.Name == className).FirstOrDefault();
808+
809+
return property != null ? property.GetValue(customMethods).ToString() : string.Empty;
810+
}
802811
#>

Templates/Android/extensions/EntityRequestBuilder.java.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
public <#=TypeRequestBuilder(c)#>(final String requestUrl, final <#=IBaseClientType()#> client, final java.util.List<Option> requestOptions) {
1919
super(requestUrl, client, requestOptions);
2020
}
21+
22+
<#=AddCustomCode(TypeRequestBuilder(c))#>
2123
}

Templates/Android/extensions/IEntityRequestBuilder.java.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
<#=CreateInterfaceDef(ITypeRequestBuilder(c), IBaseTypeRequestBuilder(c))#>
1010

11+
<#=AddCustomCode(ITypeRequestBuilder(c))#>
1112
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.Android
8+
{
9+
public class CustomMethods
10+
{
11+
public const string DriveItemRequestBuilder =
12+
" @Override\r\n" +
13+
" public IDriveItemRequestBuilder getItemWithPath(final String path) {\r\n" +
14+
" return new DriveItemRequestBuilder(getRequestUrl() + \":/\" + path + \":\", getClient(), null);\r\n" +
15+
" }";
16+
17+
public const string IDriveItemRequestBuilder =
18+
" /**\r\n" +
19+
" * Gets the item request builder for the specified item path\r\n" +
20+
" * @param path The path to the item\r\n" +
21+
" * @return The request builder for the specified item\r\n" +
22+
" */\r\n" +
23+
" IDriveItemRequestBuilder getItemWithPath(final String path);";
24+
25+
public const string IThumbnailSetRequestBuilder =
26+
" /**\r\n" +
27+
" * Gets a request for a thumbnail of a specific size\r\n" +
28+
" * @param size The size to request (typically: small, medium, large)\r\n" +
29+
" * @return The request builder for that thumbnail size\r\n" +
30+
" */\r\n" +
31+
" IThumbnailRequestBuilder getThumbnailSize(final String size);";
32+
33+
public const string ThumbnailSetRequestBuilder =
34+
" @Override\r\n" +
35+
" public IThumbnailRequestBuilder getThumbnailSize(final String size) {\r\n" +
36+
" return new ThumbnailRequestBuilder(getRequestUrlWithAdditionalSegment(size), getClient(), /* options */ null);\r\n" +
37+
" }";
38+
}
39+
}

0 commit comments

Comments
 (0)