當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。