Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "gets or sets" rule for the model template in the CSharp code generator #989

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
30 changes: 30 additions & 0 deletions AutoRest/Generators/CSharp/CSharp/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,36 @@ private static bool ShouldValidate(this IType model)
return false;
}

/// <summary>
/// Format the documentation of a property properly with the correct getters and setters. Note that this validation will
/// only acryonyms and article words.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor issue: looks like the last sentence of this method summary has a missing word and typo (acronyms).

/// </summary>
/// <param name="property">The given property documentation to format</param>
/// <returns></returns>
public static string GetFormattedPropertyDocumentation(PropertyTemplateModel property)
{
if (string.IsNullOrEmpty(property.Documentation))
{
return property.Documentation.EscapeXmlComment();
}

string documentation = property.IsReadOnly ? "Gets " : "Gets or sets ";

string firstWord = property.Documentation.Split(' ').First();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you trim the start of the Documetation to ensure there aren't any leading spaces?

Copy link
Contributor Author

@brnleehng brnleehng May 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I'll make that change

if (firstWord.Length <= 1)
{
documentation += char.ToLower(property.Documentation[0]) + property.Documentation.Substring(1);
}
else
{
documentation += firstWord.ToUpper() == firstWord
? property.Documentation
: char.ToLower(property.Documentation[0]) + property.Documentation.Substring(1);
}

return documentation.EscapeXmlComment();
}

/// <summary>
/// Format the value of a sequence given the modeled element format. Note that only sequences of strings are supported
/// </summary>
Expand Down
13 changes: 2 additions & 11 deletions AutoRest/Generators/CSharp/CSharp/Templates/ModelTemplate.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using Microsoft.Rest.Generator.ClientModel
@using Microsoft.Rest.Generator.Utilities
@using Microsoft.Rest.Generator
@using Microsoft.Rest.Generator.CSharp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this using necessary? The ShouldValidateChain() method is called in this template and is also defined in ClientModelExtensions.cs, but we didn't need the using before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@inherits Microsoft.Rest.Generator.Template<Microsoft.Rest.Generator.CSharp.ModelTemplateModel>
@Header("// ")
@EmptyLine
Expand Down Expand Up @@ -108,18 +109,8 @@ namespace @(Settings.Namespace).Models
@EmptyLine
@foreach (var property in Model.PropertyTemplateModels.Where(p => !p.IsConstant))
{
string firstWord = property.Documentation.Split(' ').First();
string documentation = string.Empty;
if (firstWord.Length <= 1)
{
documentation = char.ToLower(property.Documentation[0]) + property.Documentation.Substring(1);
}
else
{
documentation = firstWord.ToUpper() == firstWord ? property.Documentation : char.ToLower(property.Documentation[0]) + property.Documentation.Substring(1);
}
@:/// <summary>
@:@WrapComment("/// ", property.IsReadOnly ? "Gets " + documentation.EscapeXmlComment() : "Gets or sets " + documentation.EscapeXmlComment())
@:@WrapComment("/// ", ClientModelExtensions.GetFormattedPropertyDocumentation(property))
@:/// </summary>
if (property.Type.IsPrimaryType(KnownPrimaryType.Date))
{
Expand Down