2023-06-09 11:33:53 +02:00

68 lines
1.1 KiB
Plaintext

include::../why.adoc[]
[source,csharp,diff-id=1,diff-type=noncompliant]
----
class Outer
{
public static int A;
public class Inner
{
public int A; // Noncompliant
public int MyProp
{
get => A; // Returns inner A. Was that intended?
}
}
}
----
Here's an example of compliant code after renaming the inner class member, this way the property will return the `Outer` A:
[source,csharp,diff-id=1,diff-type=compliant]
----
class Outer
{
public static int A;
public class Inner
{
public int B; // Compliant
public int MyProp
{
get => A; // Returns outer A
}
}
}
----
Or if you want to reference the `Inner` A field:
[source,csharp]
----
class Outer
{
public static int B;
public class Inner
{
public int A; // Compliant
public int MyProp
{
get => A; // Returns inner A
}
}
}
----
== Resources
=== Documentation
* https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions[Common Coding Conventions]
* https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/nested-types[Nested Types]
include::../rspecator.adoc[]