You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 9, 2026. It is now read-only.
generator should warn about type names matching enclosing package names #982
x DO NOT use the same name for a namespace and a type in that namespace.
In C#, it's "bad" to have a type which has the same name as its parent namespace. This can result in unintentional ambiguity when attempting to use a type, and headscratching error messages:
type name Foo does not exist in Foo.Foo
This is easy to avoid in "normal" hand-written C# code, but this pattern is extremely common in Android bindings because we PascalCase the original Java package names.
Thus, consider com.google.zxing.aztec.decoder.Decoder: our default naming algorithm would produce Com.Google.Zxing.Aztec.Decoder.Decoder, which triggers our "DO NOT use…" scenario of having a type with the same name as its enclosing namespace.
We don't need to stretch to external bindings for this; core Android hits this as well:
The typical fix is to "pluralize" the containing namespace, e.g. turning android.gesture into Android.Gestures.
Currently, it's a manual effort to "know about" and look for this problem when adding or updating bindings, and we don't always remember to do this check.
Proposal
Update generator to check the enclosing package/namespace name and see if it matches the type name, in a case-insensitive manner. If we find a type within a matching namespace, we should emit a warning.
The warning should take post-managedName values into consideration, so that the warning can be reasonably fixed.
The warning message text should describe how to fix the warning.
The warning should use a "unique" number so that the warning can be disabled, in case the warning cannot be fixed.
Example:
warning BG1234: Type `Example.Example` has a type name which matches the enclosing namespace name.
warning BG1234: Please consider updating Metadata.xml to contain:
warning BG1234: <ns-replace source="example" replacement="Examples" />
Activity
[generator] BG8403 when type name matches enclosing namespace name (#…
Bump to xamarin/java.interop/main@032f1e71 (#7180)
[generator] BG8403 when type name matches enclosing namespace name (#…