Name Processor

The NameProcessor allows you to fully customize how element names in UXML files are converted into C# property names and class names. It also provides a way to programmatically ignore certain elements during script generation.

By default, AutoFields uses its internal naming logic, but you can override this by implementing a custom name processor. To do so:

  1. Create a class that implements the AutoFields.INameProcessor interface (or inherits from NameProcessor).

  2. Mark the class with the [NameProcessor] attribute.

  3. Your custom processor will be automatically discovered and used during code generation.

Use Cases

  • Customize naming conventions (e.g., PascalCase, snake_case, etc.)

  • Ignore specific UI elements based on name patterns

  • Rename elements based on internal rules (e.g., remove prefixes)

  • Define class names differently based on UXML filenames

Interface: INameProcessor

namespace AutoFields
{
    public interface INameProcessor
    {
        void Init(GenerationSettings settings);
        bool ShouldIgnore(string uiName);
        string GetPropertyName(string uiName);
        string GetClassName(string uxmlName);
    }
}

Method Descriptions

  • Init(GenerationSettings settings) Called during initialization. You can use this to access generation settings and prepare internal data.

  • ShouldIgnore(string uiName) Return true to exclude code generation for a given UI element name.

  • GetPropertyName(string uiName) Return a valid C# property name for the specified UI element name.

  • GetClassName(string uxmlName) Return the class name that should be generated for a given UXML file.

Creating a Custom Name Processor

To define a custom processor, you can inherit from NameProcessor or implement INameProcessor directly. The class must be marked with the [NameProcessor] attribute to be recognized.

Example:

using AutoFields;

[NameProcessor]
public class CustomNameProcessor : NameProcessor
{
    public override string GetPropertyName(string uiName)
    {
        // Example: strip prefix and convert to PascalCase
        return ConvertToPascalCase(RemovePrefix(uiName, "ui-"));
    }

    public override bool ShouldIgnore(string uiName)
    {
        // Ignore all elements starting with "debug-"
        return uiName.StartsWith("debug-");
    }
}

Built-in Behavior

AutoFields includes a default implementation of NameProcessor that:

  • Ignores elements based on the Ignored Name Masks settings (with * wildcard support).

  • Converts names to valid C# property names automatically.

Advanced users can override this behavior entirely by providing a custom class.

Notes

  • Only one NameProcessor will be used during generation — the first one found with the [NameProcessor] attribute.

  • Custom processors must be located in an accessible assembly that is loaded when Unity compiles the project.

  • The processor is selected once during script generation. Changes require recompilation to take effect.