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:
Create a class that implements the
AutoFields.INameProcessorinterface (or inherits fromNameProcessor).Mark the class with the
[NameProcessor]attribute.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
trueto 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
NameProcessorwill 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.