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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request #12

Closed
Randolphjand opened this issue Jun 5, 2022 · 3 comments
Closed

Feature Request #12

Randolphjand opened this issue Jun 5, 2022 · 3 comments
Labels
area: code-generator The issue is related to the code generator engine area: parsing The issue is related to the parsing engine enhancement New feature or request
Milestone

Comments

@Randolphjand
Copy link

Is there a way to support using dashes in naming the fields? When I try to modify existing uxml files that use dashes in the names, it does not work. I am talking about when someone names a field something like a label field and they name it main-label which seems to be a kind of standard from many toolkit existing projects that I have found.

@Eastrall
Copy link
Owner

Eastrall commented Jun 5, 2022

Hello,

Right now Rosalina doesn't support property names with snake-case. What the generator does, it that it takes the element name attribute and just uses it for the C# code generation.
For example:

<ui:Label name="title-label" text="Information" />

this will generate the following property in C#

public Label title-label { get; private set; }

Of course, has a feature, we could imagine implementing something that converts the names that has - (dashes) into PascalCase; if we take the UXML above, that would result in a C# property:

public Label TitleLabel { get; private set; }

Thus, by doing this, we will have to check if there is not another TitleLabel in the document:

<ui:Label name="title-label" text="Information" />
<ui:Label name="TitleLabel" text="Information" />

This will result in a generation error.

Thank you for suggesting this feature. I am going to plan this and do the appropriate changes. 😉

@Eastrall Eastrall added enhancement New feature or request area: parsing The issue is related to the parsing engine area: code-generator The issue is related to the code generator engine labels Jun 5, 2022
@Blackclaws
Copy link

Here you go:

public static class StringExtensions
{
    public static string ToUpperStart(this string s)
    {
        if (s.Length == 0) return s;
        if (s.Length == 1) return s.ToUpper();
        return s.Substring(0, 1).ToUpper() + s.Substring(1);
    }

    public static string KebabToCamelCase(this string s)
    {
        var parts = s.Split('-');
        var builder = new StringBuilder();
        foreach (var part in parts)
        {
            builder.Append(part.ToUpperStart());
        }

        return builder.ToString();
    }
}

Licensing this snippet CC0 or MIT whichever you prefer.

@Eastrall
Copy link
Owner

Released in version 1.1.0: https://github.com/Eastrall/Rosalina/releases/tag/v1.1.0

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 area: parsing The issue is related to the parsing engine enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants