当前位置: 首页>>代码示例>>C#>>正文


C# Accessor.ContainsModifier方法代码示例

本文整理汇总了C#中Accessor.ContainsModifier方法的典型用法代码示例。如果您正苦于以下问题:C# Accessor.ContainsModifier方法的具体用法?C# Accessor.ContainsModifier怎么用?C# Accessor.ContainsModifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Accessor的用法示例。


在下文中一共展示了Accessor.ContainsModifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IncludeSetAccessorInDocumentation

        /// <summary>
        /// Determines whether to reference the set accessor within the property's summary documentation.
        /// </summary>
        /// <param name="property">The property.</param>
        /// <param name="setAccessor">The set accessor.</param>
        /// <returns>Returns true to reference the set accessor in the summary documentation, or false to omit it.</returns>
        private static bool IncludeSetAccessorInDocumentation(Property property, Accessor setAccessor)
        {
            Param.AssertNotNull(property, "property");
            Param.AssertNotNull(setAccessor, "setAccessor");

            // If the set accessor has the same access modifier as the property, always include it in the documentation.
            // Accessors get 'private' access modifiers by default if no access modifier is defined, in which case they
            // default to having the access of their parent property. Also include documentation for the set accessor
            // if it appears to be private but it does not actually define the 'private' keyword.
            if (setAccessor.AccessModifierType == property.AccessModifierType ||
                (setAccessor.AccessModifierType == AccessModifierType.Private && !setAccessor.ContainsModifier(TokenType.Private)))
            {
                return true;
            }

            var actualAccess = property.ActualAccessLevel;

            // If the set accessor has internal access, and the property also has internal or protected internal access, 
            // then include the set accessor in the docs since it effectively has the same access as the overall property.
            if (setAccessor.AccessModifierType == AccessModifierType.Internal &&
                (actualAccess == AccessModifierType.Internal || actualAccess == AccessModifierType.ProtectedAndInternal))
            {
                return true;
            }

            // If the property is effectively private (contained within a private class), and the set accessor has any access modifier other than private, then
            // include the set accessor in the documentation. Within a private class, other access modifiers on the set accessor are meaningless.
            if (actualAccess == AccessModifierType.Private && !setAccessor.ContainsModifier(TokenType.Private))
            {
                return true;
            }

            // If the set accessor has protected access, then always include it in the docs since it will be visible to any
            // class that inherits from this class.
            if (setAccessor.AccessModifierType == AccessModifierType.Protected || setAccessor.AccessModifierType == AccessModifierType.ProtectedInternal)
            {
                return true;
            }

            // Otherwise, omit the set accessor from the documentation since its access is more restricted
            // than the access of the property.
            return false;
        }
开发者ID:jonthegiant,项目名称:StyleCop,代码行数:49,代码来源:DocumentationRules.cs


注:本文中的Accessor.ContainsModifier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。