Подія
17 бер., 21 - 21 бер., 10
Приєднайтеся до серії нарад, щоб створити масштабовані рішення зі ШІ на основі реальних випадків використання з колегами-розробниками та експертами.
Зареєструватися заразЦей браузер більше не підтримується.
Замініть його на Microsoft Edge, щоб користуватися перевагами найновіших функцій, оновлень безпеки та технічної підтримки.
Property | Value |
---|---|
Rule ID | CA1034 |
Title | Nested types should not be visible |
Category | Design |
Fix is breaking or non-breaking | Breaking |
Enabled by default in .NET 9 | No |
An externally visible type contains an externally visible type declaration. Nested enumerations, protected types, and builder patterns are exempt from this rule.
A nested type is a type declared within the scope of another type. Nested types are useful for encapsulating private implementation details of the containing type. Used for this purpose, nested types should not be externally visible.
Do not use externally visible nested types for logical grouping or to avoid name collisions; instead, use namespaces.
Nested types include the notion of member accessibility, which some programmers do not understand clearly.
Protected types can be used in subclasses and nested types in advance customization scenarios.
If you do not intend the nested type to be externally visible, change the type's accessibility. Otherwise, remove the nested type from its parent. If the purpose of the nesting is to categorize the nested type, use a namespace to create the hierarchy instead.
Do not suppress a warning from this rule.
The following example shows a type that violates the rule.
public class ParentType
{
public class NestedType
{
public NestedType()
{
}
}
public ParentType()
{
NestedType nt = new NestedType();
}
}
Imports System
Namespace ca1034
Class ParentType
Public Class NestedType
Sub New()
End Sub
End Class
Sub New()
End Sub
End Class
End Namespace
Відгук про .NET
.NET – це проект із відкритим кодом. Виберіть посилання, щоб надати відгук:
Подія
17 бер., 21 - 21 бер., 10
Приєднайтеся до серії нарад, щоб створити масштабовані рішення зі ШІ на основі реальних випадків використання з колегами-розробниками та експертами.
Зареєструватися зараз