Skip to content

Renaming namespaces or types or members

Jonathan Pobst edited this page Feb 7, 2024 · 5 revisions

The default names of namespaces, types, members, and parameters generated for a Java library may not what you want.

Some reasons may be:

  • Different desired capitalization (Androidx instead of AndroidX)
  • Different .NET conventions (package com.company.json versus namespace Company.Json)
  • Java allows some identifiers that are not valid in C#, like starting with a number (1Drive)
    • This can cause a compilation error like: Error CS1001: Identifier expected
  • A collision between field/method/nested type names, like having a class that contains a field and a nested type with the same name
    • This can cause a compilation error like: Error CS0102: The type 'MyClass' already contains a definition for 'ErrorCode'

These names can be changed using the managedName attribute of metadata:

<!-- Namespace -->
<attr path="/api/package[@name='com.example']" name="managedName">Example</attr>

<!-- Class-->
<attr path="/api/package[@name='com.example']/class[@name='4Square']" name="managedName">FourSquare</attr>

<!-- Interface-->
<attr path="/api/package[@name='com.example']/interface[@name='4SquareListener']" name="managedName">IFourSquareListener</attr>

<!-- Field-->
<attr path="/api/package[@name='com.example']/class[@name='MyClass']/field[@name='errorCode']" name="managedName">ErrorCodeField</attr>

<!-- Method-->
<attr path="/api/package[@name='com.example']/class[@name='MyClass']/method[@name='2Object']" name="managedName">ToObject</attr>

<!-- Parameter-->
<attr path="/api/package[@name='com.example']/class[@name='MyClass']/method[@name='getItem']/parameter[@name='p0']" name="managedName">index</attr>

Note that the exact value you provide will be used (including capitalization), the normal fixups will not be performed on the managedName.

For example, when changing the interface above, you will need to add the I prefix yourself if using managedName.