episerver

Identify Select Many/Select One attribute of Selection factory


Is there a way to identify may be through reflection or any other way to identify a property if it is select one or select many.

I have a common selection factory that is both select one & select many as shown in the below image.

enter image description here

I need to perform some operations based on the type of dropdown it is. So is there is any way to determine the select one or many attribute in the selection factory class

Any inputs is appreciated.


Solution

  • Perhaps I'm missing something, but that sounds like code smell? You should probably refactor the common logic into something separate, and then create two separate selection factories with whatever differs between the two.

    With that said, you could probably do something like the following inside your SelectionFactory class:

    public IEnumerable GetSelections(ExtendedMetadata metadata)
    {
        if(metadata.Attributes.OfType<SelectOneAttribute>()?.Any() ?? false) {
           // One
        } else {
           // Many
        }
    }