Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
<Reference Include="System.Core" />
<Reference Include="Vipr.Core">
<HintPath>..\submodules\vipr\src\Core\Vipr.Core\bin\Debug\Vipr.Core.dll</HintPath>
<HintPath>..\submodules\vipr\src\Core\Vipr.Core\bin\Release\Vipr.Core.dll</HintPath>
</Reference>
<Reference Include="Vipr.Reader.OData.v4">
<HintPath>..\submodules\vipr\src\Readers\Vipr.Reader.OData.v4\bin\Debug\Vipr.Reader.OData.v4.dll</HintPath>
<HintPath>..\submodules\vipr\src\Readers\Vipr.Reader.OData.v4\bin\Release\Vipr.Reader.OData.v4.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -73,4 +71,4 @@
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
</Project>
</Project>
6 changes: 4 additions & 2 deletions Templates/CSharp/Base/EntityRequestBuilder.Base.template.tt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public string GetRequestBuilderProperty(string propertyName, string urlValue, st

public string GetCollectionPropertyRequestBuilderProperty(string entityName, OdcmProperty odcmProperty)
{
var propertyName = this.GetPropertyName(odcmProperty).GetSanitizedPropertyName();
var propertyName = this.GetPropertyName(odcmProperty);
propertyName = propertyName.GetSanitizedPropertyName(suffix: propertyName == "Request" ? "_" : null);
var propertyPrefix = string.Concat(entityName, this.GetPropertyName(odcmProperty));
var collectionRequestBuilder = odcmProperty.IsReference()
? this.GetCollectionWithReferencesRequestBuilderString(propertyPrefix)
Expand All @@ -153,7 +154,8 @@ public string GetCollectionPropertyRequestBuilderProperty(string entityName, Odc

public string GetNonCollectionRequestBuilderProperty(OdcmProperty odcmProperty)
{
var propertyName = this.GetPropertyName(odcmProperty).GetSanitizedPropertyName();
var propertyName = this.GetPropertyName(odcmProperty);
propertyName = propertyName.GetSanitizedPropertyName(suffix: propertyName == "Request" ? "_" : null);
var propertyPrefix = this.GetPropertyTypeName(odcmProperty);
var propertyRequestBuilder = odcmProperty.IsReference()
? this.GetWithReferenceRequestBuilderString(propertyPrefix)
Expand Down
8 changes: 5 additions & 3 deletions Templates/CSharp/Base/IEntityRequestBuilder.Base.template.tt
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,9 @@ public string GetRequestBuilderProperty(string propertyName, string requestBuild
}

public string GetCollectionPropertyRequestBuilderProperty(string entityName, OdcmProperty odcmProperty)
{
var propertyName = this.GetPropertyName(odcmProperty).GetSanitizedPropertyName();
{
var propertyName = this.GetPropertyName(odcmProperty);
propertyName = propertyName.GetSanitizedPropertyName(suffix: propertyName == "Request" ? "_" : null);
var propertyPrefix = string.Concat(entityName, this.GetPropertyName(odcmProperty));
var collectionRequestBuilder = odcmProperty.IsReference()
? this.GetCollectionWithReferencesRequestBuilderString(propertyPrefix)
Expand All @@ -110,7 +111,8 @@ public string GetCollectionPropertyRequestBuilderProperty(string entityName, Odc

public string GetNonCollectionRequestBuilderProperty(OdcmProperty odcmProperty)
{
var propertyName = this.GetPropertyName(odcmProperty).GetSanitizedPropertyName();
var propertyName = this.GetPropertyName(odcmProperty);
propertyName = propertyName.GetSanitizedPropertyName(suffix: propertyName == "Request" ? "_" : null);
var propertyPrefix = this.GetPropertyTypeName(odcmProperty);
var propertyRequestBuilder = odcmProperty.IsReference()
? this.GetWithReferenceRequestBuilderString(propertyPrefix)
Expand Down
35 changes: 19 additions & 16 deletions src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ public static string GetSanitizedLongDescription(this OdcmProperty property)
return null;
}

public static string GetSanitizedPropertyName(this OdcmProperty property)
public static string GetSanitizedPropertyName(this OdcmProperty property, string prefix = null, string suffix = null)
{
return GetSanitizedPropertyName(property.Name);
return GetSanitizedPropertyName(property.Name, prefix, suffix);
}

public static string GetSanitizedClassName(this OdcmClass odcmClass)
{
return GetSanitizedClassName(odcmClass.Name, odcmClass);
}

public static string GetSanitizedPropertyName(this string property, string prefix = null)
public static string GetSanitizedPropertyName(this string property, string prefix = null, string suffix = null)
{
return GetSanitizedPropertyName(property, null, prefix);
return GetSanitizedPropertyName(property, null, prefix, suffix);
}

/// <summary>
Expand All @@ -248,34 +248,37 @@ public static string GetSanitizedPropertyName(this string property, string prefi
/// <param name="odcmProperty">An OdcmProperty. Use the property that you want to sanitize.</param>
/// <param name="prefix">The prefix to use on this property.</param>
/// <returns></returns>
public static string GetSanitizedPropertyName(this string property, OdcmProperty odcmProperty, string prefix = null)
public static string GetSanitizedPropertyName(this string property, OdcmProperty odcmProperty, string prefix = null, string suffix = null)
{
string result = property;
if (GetReservedNames().Contains(property))
{
var reservedPrefix = string.IsNullOrEmpty(prefix) ? DefaultReservedPrefix : prefix;

logger.Info("Property \"{0}\" is a reserved word in .NET. Converting to \"{1}{0}\"", property.ToUpperFirstChar(), reservedPrefix);
return string.Concat(reservedPrefix, property.ToUpperFirstChar());
result = string.Concat(reservedPrefix, property.ToUpperFirstChar());
}

// Check whether the propertyObject is null (means they called the extension from a string).
// Check whether the property name is the same as the class name.
// Only constructor members may be named the same as the class name.
if (odcmProperty != null && property == odcmProperty.Class.Name.ToUpperFirstChar())
else if (odcmProperty != null && property == odcmProperty.Class.Name.ToUpperFirstChar())
{
// Check whether the propertyObject is null (means they called the extension from a string).
// Check whether the property name is the same as the class name.
// Only constructor members may be named the same as the class name.

// Check whether the property type is the same as the class name.
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Class.Name.ToUpperFirstChar())
{
// Name the property: {metadataName} + "Property"
logger.Info("Property type \"{0}\" has the same name as the class. Converting to \"{0}Property\"", property);
return string.Concat(property, "Property");
result = string.Concat(property, "Property");
}
else
{
// Name the property by its type. Sanitize it in case the type is a reserved name.
result = odcmProperty.Projection.Type.Name.ToUpperFirstChar().GetSanitizedPropertyName();
}

// Name the property by its type. Sanitize it in case the type is a reserved name.
return odcmProperty.Projection.Type.Name.ToUpperFirstChar().GetSanitizedPropertyName();
}

return property;
return result+suffix;
}

public static string GetSanitizedClassName(this string className, OdcmClass odcmClass)
Expand Down