Skip to content

GetElementDescriptorByTypeName should not be case sensitive #7304

@sfmskywalker

Description

@sfmskywalker

The issue becomes apparent when you create an element snippet and you want to turn that snippet into a widget (leveraging the Element Wrapper part).

When you configure the ElementWrapperPart with the type name of the snippet element, you currently need to be aware that this type is based on the shape type name of the Razor view that represents the snippet. The Razor shape template harvester, however, generates a shape type name based on the Razor view file name, using all lower case.

For example, if I create a Razorfile called "MyLogoSnippet.cshtml", the shape type name will become "mylogosnippet". This name is used in the SnippetElementHarvester as the element's type name.

If I now configure the ElementWrapperPart with an element type name of MyLogoSnippet, the part will not be able to find any elements by that name, because GetElementDescriptorByTypeName is case-sensitive:

public ElementDescriptor GetElementDescriptorByTypeName(DescribeElementsContext context, string typeName) {
    var elements = DescribeElements(context);
    var element = elements.SingleOrDefault(x => x.TypeName == typeName);

    return element;
}

To fix this situation, a case-insensitive predicate should be used:

var element = elements.SingleOrDefault(x => String.Equals(x.TypeName, typeName, StringComparison.OrdinalIgnoreCase));

That way, you don't have to be aware of using the all lower case "mylogosnippet" value for the element type name on the ElementWrapperPart.

This seems to be a non-breaking change, so I would propose to fix this as part of 1.10.x.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions