Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悶 [BUG] - Issue generating properties assignment for elements with kebab-case names #21

Closed
Eastrall opened this issue Sep 13, 2022 · 1 comment
Labels
area: code-generator The issue is related to the code generator engine bug Something isn't working

Comments

@Eastrall
Copy link
Owner

Eastrall commented Sep 13, 2022

馃悶Bug Report

Version: 1.2.0

Current behavior

When using kebab-case names in visual elements, such as:

<ui:UXML xmlns:ui="UnityEngine.UIElements" ...>
    <ui:VisualElement>
        <ui:Button text="Button text" name="some-button" />
    </ui:VisualElement>
</ui:UXML>

Rosalina binding generator generates bad query names in auto-generated code:

public Button SomeButton { get; private set; }

...

public void InitializeDocument()
{
    SomeButton = (Button)Root?.Q("SomeButton");
}

And then throws an NullReferenceException when interacting with the property.

Expected Behavior

Rosalina bindings generator should generate the appropriate query:

public Button SomeButton { get; private set; }

...

public void InitializeDocument()
{
    SomeButton = (Button)Root?.Q("some-button");
}

Steps to Reproduce

  1. Create a new UI Document
  2. Add an element
  3. Set the name in kebab-case
  4. Try to interact with the generated property.

Possible Solution

Might be related to this statement:

SyntaxFactory.Literal(uiProperty.Name)

We are using the Name property, which should be only used for generating the elements properties. Instead, I believe we should use the OriginalName since it contains the element's raw name as described in UXML.

/// <summary>
/// Gets the UI property name that is used for generating C# properties during the code generation process.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the UI property name as described in the UXML file.
/// </summary>
public string OriginalName { get; }
public UIProperty(string type, string name)
{
TypeName = type;
Type = UIPropertyTypes.GetUIElementType(type);
OriginalName = name;
Name = name.Contains('-') ? name.ToPascalCase() : OriginalName;
}

@Eastrall Eastrall added bug Something isn't working area: code-generator The issue is related to the code generator engine labels Sep 13, 2022
@Eastrall
Copy link
Owner Author

Fixed in v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: code-generator The issue is related to the code generator engine bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant