-
Notifications
You must be signed in to change notification settings - Fork 741
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
Changes from 1 commit
1afef7d
713465c
786f94e
40e49d0
1288102
dc30d8a
896616b
2976efe
1fcdafa
18ec9cd
2622aaa
45618ea
54beae9
53e7c55
ac7232d
0f01672
431b98e
423bdfa
8641c7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
/// </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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
@using Microsoft.Rest.Generator.ClientModel | ||
@using Microsoft.Rest.Generator.Utilities | ||
@using Microsoft.Rest.Generator | ||
@using Microsoft.Rest.Generator.CSharp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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)) | ||
{ | ||
|
There was a problem hiding this comment.
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).