Skip to content

Commit 58a8d65

Browse files
committed
Special case for collection request builders - handle case when there is a method named item.
1 parent a0b3520 commit 58a8d65

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Templates/CSharp/Base/ICollectionRequestBuilder.Base.template.tt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,18 @@ public string GetCollectionIndexRequestBuilder(OdcmProperty odcmProperty)
2727
var propTypeName = this.GetPropertyTypeName(odcmProperty);
2828
var entityRequestBuilder = this.GetPropertyTypeRequestBuilderName(odcmProperty);
2929

30-
return this.GetIndexRequestBuilder(propTypeName, entityRequestBuilder);
30+
// In case there is an action or function with the name of item. This is to avoid CS0102
31+
// https://msdn.microsoft.com/en-US/library/26f2y168%28v=VS.90%29.aspx
32+
var allMethods = new List<OdcmMethod>();
33+
foreach (var method in odcmProperty.Projection.Type.AsOdcmClass().Methods)
34+
{
35+
allMethods.Add(method);
36+
allMethods.AddRange(method.Overloads);
37+
}
38+
39+
var hasItemMethod = allMethods.Exists(x => x.Name.Equals("item")) ? true : false;
40+
41+
return this.GetIndexRequestBuilder(propTypeName, entityRequestBuilder, hasItemMethod);
3142
}
3243

3344

@@ -73,7 +84,7 @@ public string GetCollectionWithReferencesRequestMethodWithOptions(OdcmProperty o
7384
// Indexer properties
7485
// -------------------------------------------------------------
7586
// Creates an indexer for the specified property name and requestBuilderTypeName
76-
public string GetIndexRequestBuilder(string propertyName, string requestBuilderTypeName)
87+
public string GetIndexRequestBuilder(string propertyName, string requestBuilderTypeName, bool hasItemMethod)
7788
{
7889
var stringBuilder = new StringBuilder();
7990

@@ -87,6 +98,11 @@ public string GetIndexRequestBuilder(string propertyName, string requestBuilderT
8798
stringBuilder.Append(Environment.NewLine);
8899
stringBuilder.AppendFormat(" /// <returns>The <see cref=\"I{0}\"/>.</returns>", requestBuilderTypeName);
89100
stringBuilder.Append(Environment.NewLine);
101+
if (hasItemMethod)
102+
{
103+
stringBuilder.AppendFormat(" [System.Runtime.CompilerServices.IndexerName(\"ThisItem\")]"); // Special case for methods named Item.
104+
stringBuilder.Append(Environment.NewLine);
105+
}
90106
stringBuilder.AppendFormat(" I{0} this[string id] {{ get; }}", requestBuilderTypeName);
91107

92108
return stringBuilder.ToString();
@@ -125,7 +141,7 @@ public string GetCollectionWithReferencesIndexRequestBuilder(OdcmProperty odcmPr
125141
var propTypeName = this.GetPropertyTypeName(odcmProperty);
126142
var entityRequestBuilder = this.GetPropertyTypeWithReferenceRequestBuilderName(odcmProperty);
127143

128-
return this.GetIndexRequestBuilder(propTypeName, entityRequestBuilder);
144+
return this.GetIndexRequestBuilder(propTypeName, entityRequestBuilder, false);
129145
}
130146

131147
#>

0 commit comments

Comments
 (0)