예제 #1
0
        [DisableRule("D1042", "IdenticalMethods")]                      // TODO: matches NetNaming
        public void VisitType(TypeDefinition type)
        {
            if (type.Name.Length >= 4)                                          // weird generated types like P1`1
            {
                if (char.IsLetter(type.Name[0]) && char.IsDigit(type.Name[1]) && type.Name[2] == '`' && char.IsDigit(type.Name[3]))
                {
                    return;
                }
            }

            if (m_needsCheck)
            {
                // Type name must be PascalCase.
                if (!NamingUtils.IsPascalCase(type.Name))
                {
                    m_details += "Type: " + type.Name + ". ";
                }

                if (type.IsInterface)
                {
                    if (type.Name[0] != 'I')
                    {
                        m_details += "Interface: " + type.Name + ". ";
                    }
                }
            }
        }
예제 #2
0
        public void VisitMethod(MethodDefinition method)
        {
            if (!m_needsCheck || method.Name.StartsWith("yy"))
            {
//			if (!m_needsCheck || method.Name.StartsWith("yy") || method.IsCompilerGenerated() || method.ToString().Contains("AnonymousMethod"))
                return;
            }

            if (method.Name.StartsWith("<"))
            {
                return;
            }

            // Method name must be PascalCase.
            if (!method.IsSpecialName && !NamingUtils.IsPascalCase(method.Name))
            {
                m_details += "Method: " + method.Name + ". ";
            }

            // Parameters must be camelCase.
            foreach (ParameterDefinition param in method.Parameters)
            {
                if (!NamingUtils.IsCamelCase(param.Name))
                {
                    m_details = string.Format("{0}Argument: {1}. ", m_details, param.Name);
                }
            }
        }
예제 #3
0
        public void VisitField(FieldDefinition field)
        {
            if (!m_needsCheck)
            {
                return;
            }

            if (field.Name.IndexOf("<") >= 0)                   // auto-property
            {
                return;
            }

            if (field.Name[0] == '$')
            {
                return;
            }

            // Protected and private fields must be camelCase. Public and internal fields must
            // be PascalCase.
            if ((m_type.Attributes & TypeAttributes.Serializable) != TypeAttributes.Serializable)
            {
                if ((field.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        m_details = string.Format("{0}Public Field: {1}. ", m_details, field.Name);
                    }
                }
                else if ((field.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        m_details = string.Format("{0}Internal Field: {1}. ", m_details, field.Name);
                    }
                }
                else if ((field.Attributes & FieldAttributes.Literal) == FieldAttributes.Literal)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        m_details = string.Format("{0}Constant Field: {1}. ", m_details, field.Name);
                    }
                }
                else
                {
                    if (!NamingUtils.IsCamelCase(field.Name))
                    {
                        m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                    }

                    // mUpperCase is not legit
                    if (field.Name.Length > 1)
                    {
                        if (field.Name[0] == 'm' && char.IsUpper(field.Name[1]))
                        {
                            m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                        }
                    }
                }
            }
        }
예제 #4
0
        public void VisitProperty(PropertyDefinition prop)
        {
            if (!m_needsCheck)
            {
                return;
            }

            if (!NamingUtils.IsPascalCase(prop.Name))
            {
                m_details = string.Format("{0}Property: {1}. ", m_details, prop.Name);
            }
        }
예제 #5
0
        public void VisitEvent(EventDefinition evt)
        {
            if (!m_needsCheck)
            {
                return;
            }

            if (!NamingUtils.IsPascalCase(evt.Name))
            {
                m_details = string.Format("{0}Event: {1}. ", m_details, evt.Name);
            }
        }
예제 #6
0
        public void VisitField(FieldDefinition field)
        {
            if (!m_needsCheck)
            {
                return;
            }

            if (field.Name.IndexOf("<") >= 0)                   // auto-property
            {
                return;
            }

            if (field.Name[0] == '$')
            {
                return;
            }

            // Protected and private fields must be divided_by_underscores.
            if ((field.Attributes & FieldAttributes.FieldAccessMask) != FieldAttributes.Public)
            {
                if ((m_type.Attributes & TypeAttributes.Serializable) != TypeAttributes.Serializable)
                {
                    if ((field.Attributes & FieldAttributes.Literal) != FieldAttributes.Literal)
                    {
                        if (field.FieldType.FullName.Contains("System.EventHandler"))                           // events are special
                        {
                            if (!NamingUtils.IsPascalCase(field.Name))
                            {
                                m_details = string.Format("{0}Event: {1}. ", m_details, field.Name);
                                Log.DebugLine(this, "event field {0} isn't a pascal name", field.Name);
                            }
                        }
                        else if (!NamingUtils.IsUnderScoreName(field.Name))
                        {
                            m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                            Log.DebugLine(this, "field {0} isn't an underscore name", field.Name);
                        }

                        // m_my_name and the like are not legit
                        if (m_details.Length == 0 && field.Name.Length > 2)
                        {
                            if (field.Name[0] == 'm' && field.Name[1] == '_')
                            {
                                m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                                Log.DebugLine(this, "field {0} uses m_", field.Name);
                            }
                            else if (field.Name[0] == 's' && field.Name[1] == '_')
                            {
                                m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                                Log.DebugLine(this, "field {0} uses s_", field.Name);
                            }
                            else if (field.Name[0] == 'm' && field.Name[1] == 's' && field.Name[2] == '_')
                            {
                                m_details = string.Format("{0}Field: {1}. ", m_details, field.Name);
                                Log.DebugLine(this, "field {0} uses ms_", field.Name);
                            }
                        }
                    }
                    else
                    {
                        // except for constants
                        if (!NamingUtils.IsPascalCase(field.Name))
                        {
                            m_details = string.Format("{0}Constant: {1}. ", m_details, field.Name);
                            Log.DebugLine(this, "constant field {0} isn't pascal case", field.Name);
                        }
                    }
                }
            }
        }
예제 #7
0
        public void VisitJurassicFields(FieldDefinition field)
        {
            if (!NeedsCheck)
            {
                return;
            }

            if (field.IsPublic)
            {
                return;
            }

            if (field.Name.IndexOf("<") >= 0)                   // auto-property
            {
                return;
            }

            if (field.Name[0] == '$')
            {
                return;
            }

            if ((Type.Attributes & TypeAttributes.Serializable) != TypeAttributes.Serializable)
            {
                // Public are pascal cased.
                if ((field.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        Details = string.Format("{0}Public Field: {1}. ", Details, field.Name);
                    }
                }

                // Internal are pascal cased.
                else if ((field.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        Details = string.Format("{0}Internal Field: {1}. ", Details, field.Name);
                    }
                }

                // Literals are pascal cased.
                else if ((field.Attributes & FieldAttributes.Literal) == FieldAttributes.Literal)
                {
                    if (!NamingUtils.IsPascalCase(field.Name))
                    {
                        Details = string.Format("{0}Constant Field: {1}. ", Details, field.Name);
                    }
                }

                // Protected and private static are ms_fooBar, s_fooBar, or sFooBar, or msFooBar.
                else if (field.IsStatic)
                {
                    if (field.Name.StartsWith("ms_"))
                    {
                        if (!NamingUtils.IsCamelCase(field.Name.Substring(3)))
                        {
                            Details = string.Format("{0}Static Field: {1}. ", Details, field.Name);
                        }
                    }
                    else if (field.Name.StartsWith("s_"))
                    {
                        if (!NamingUtils.IsCamelCase(field.Name.Substring(2)))
                        {
                            Details = string.Format("{0}Static Field: {1}. ", Details, field.Name);
                        }
                    }
                    else if (field.Name.StartsWith("s"))
                    {
                        if (!NamingUtils.IsPascalCase(field.Name.Substring(1)))
                        {
                            Details = string.Format("{0}Static Field: {1}. ", Details, field.Name);
                        }
                    }
                    else if (field.Name.StartsWith("ms"))
                    {
                        if (!NamingUtils.IsPascalCase(field.Name.Substring(2)))
                        {
                            Details = string.Format("{0}Static Field: {1}. ", Details, field.Name);
                        }
                    }
                    else
                    {
                        Details = string.Format("{0}Static Field: {1}. ", Details, field.Name);
                    }
                }

                // Protected and private fields must be m_fooBar or mFooBar.
                else
                {
                    if (field.FieldType.FullName.Contains("System.EventHandler"))                       // events are special
                    {
                        if (!NamingUtils.IsPascalCase(field.Name))
                        {
                            Details = string.Format("{0}Field: {1}. ", Details, field.Name);
                        }
                    }
                    else if (field.Name.StartsWith("m_"))
                    {
                        if (!NamingUtils.IsCamelCase(field.Name.Substring(2)))
                        {
                            Details = string.Format("{0}Field: {1}. ", Details, field.Name);
                        }
                    }
                    else if (field.Name.StartsWith("m"))
                    {
                        if (!NamingUtils.IsPascalCase(field.Name.Substring(2)))
                        {
                            Details = string.Format("{0}Field: {1}. ", Details, field.Name);
                        }
                    }
                    else
                    {
                        Details = string.Format("{0}Field: {1}. ", Details, field.Name);
                    }
                }
            }
        }