1

Closed

SA1600: always includes gets documentation even if property does not have a gets

description

When adding the summary element to a property, the documents always starts with "Gets.." even if there is not a gets statement in the property.
Closed Feb 12, 2009 at 5:13 PM by andyr
Fixed.

comments

digitaldrummerj wrote Feb 12, 2009 at 1:47 PM

Here is the code to implement this in the DocumentationRules.InsertMissingElement method and code to add a test to Test1623..

Implementation:
                var getter = propertyDeclaration.Getter();
                var setter = propertyDeclaration.Setter();
                var summaryText = string.Empty;
                var valueText = string.Format("\r\n<value>The {0}.</value>", Utils.ConvertTextToSentence(declaration.DeclaredName).ToLower()); ;

                var midText = Utils.IsPropertyBoolean(propertyDeclaration) ? "a value indicating whether " : string.Empty;

                if (getter != null)
                {
                     summaryText = "Gets {0}{1}.";
                }

                if (setter != null)
                {
                    var setterAccessRight = setter.GetAccessRights();

                    if ((setterAccessRight == AccessRights.PRIVATE && propertyDeclaration.GetAccessRights() == AccessRights.PRIVATE) || setterAccessRight == AccessRights.PUBLIC ||
                        setterAccessRight == AccessRights.PROTECTED || setterAccessRight == AccessRights.PROTECTED_OR_INTERNAL || setterAccessRight == AccessRights.INTERNAL)
                    {
                         if (string.IsNullOrEmpty(summaryText))
                         {
                              summaryText = "Sets {0}{1}.";
                         }
                         else
                         {
                              summaryText = "Gets or sets {0}{1}.";
                         }
                    }
                }
Test: The property documentation should says "Sets TestOnlySetter."
     /// <summary>
     /// Used by TestOnlySetter.
     /// </summary>
     private string _testOnlySetter;

    public string TestOnlySetter
    {
         set
         {
              this._testOnlySetter = value;
         }
    }

andyr wrote Feb 12, 2009 at 5:11 PM

I've checked this in. However it defines valueText above and then doesn't use it. I also had to rename the PrepareParameterName method in Utils to ConvertTextToSetence.

digitaldrummerj wrote Feb 12, 2009 at 7:33 PM

the valueText actually was used in a patch that I submitted to add the value element to properties. That patch also included the ConvertTextToSentence method.