Skip to content
This repository was archived by the owner on Feb 26, 2022. It is now read-only.

Enum Helper Methods - #1

Merged
leekelleher merged 5 commits into
uComponents:masterfrom
tomfulton:feature/enum-helper
Jan 23, 2014
Merged

leekelleher merged 5 commits into
uComponents:masterfrom
tomfulton:feature/enum-helper

Conversation

@tomfulton

Copy link
Copy Markdown
Contributor

This is for workitem 14779

This extracts the code used by EnumCheckBoxList and EnumDropDownList into a helper method so that others can easily reuse the values specified in the Enum's custom attributes. For example, if you want to output the values on the website front-end.

I chose to return ListItem since the properties in the attribute already match perfectly - might need to be changed in the future, though, if properties are added.

I'll update the documentation with these new methods once they're finalized.

Syntax

Razor / C#

var enumListItems = uComponents.Core.EnumHelper.GetEnumListAttributeValues(typeof (SiteColour));

foreach (var listItem in enumListItems)
{
    <option value="@listItem.Value">@listItem.Text</option>
}

XSLT

<xsl:for-each select="ucomponents.enums:GetEnumListAttributeValues('YourSiteAssembly', 'SiteColour')//ListItem">
    <option value="{@Value}"><xsl:value-of select="@Text"/></option>
</xsl:for-each>

Issues

  • uComponents.Core probably isn't the best place for this. Ideally it would live in the DataTypes project, but I couldn't find a good place to put it since it applies to both the EnumCheckBoxList and EnumDropDownList datatypes.
  • Better method name than GetEnumListAttributeValues ? 😬

@leekelleher

Copy link
Copy Markdown
Contributor

Looking good, thanks Tom!

Before I merge it in, just thinking (again) about the namespace/location. We do have the "Shared" area in the DataTypes project. Maybe we could add a "Shared/Helpers" folder?

@Hendy - any feedback?

@Hendy

Hendy commented Dec 16, 2013

Copy link
Copy Markdown
Contributor

Nice one Tom :) yes, Shared/Helpers looks to be a sensible place.

@ghost ghost assigned tomfulton Jan 22, 2014
* Remove now unused variables in favor of EnumHelper
* Remove now unneeded using statements
* Update method comments
@tomfulton

Copy link
Copy Markdown
Contributor Author

@leekelleher Better late than never? ;) All set and moved to DataTypes (nice idea - missed that!)

@leekelleher

Copy link
Copy Markdown
Contributor

I'm merging in the pull-request now, good work! 👍

Although I'm not sure I like XsltExtensions having a dependency on DataTypes, so we'll review that before the next release. (Current thinking is that we move it back into Core as an internal and expose the methods in the other projects)

leekelleher added a commit that referenced this pull request Jan 23, 2014
@leekelleher
leekelleher merged commit a4f8607 into uComponents:master Jan 23, 2014
@tomfulton

Copy link
Copy Markdown
Contributor Author

@leekelleher Yeah, I was thinking about that. There could be a potential use case for having XsltExtensions rely on DataTypes, though - what if you wanted to expose an XsltExtension that relates to a DataType, such as the Url Picker? I guess its data is stored as XML anyway, so one shouldn't be needed, but maybe a DataType might want to provide some helper methods for Xslt (and/or other languages), but funnel them through centralized methods?

I'm thinking that a DataType bundling an XsltExtension isn't that much different from a PropertyEditorValueConverter, which does live separately and has a dependency on DataTypes.

That's exactly what we're doing here, but maybe there's some confusion on whether Enums are a uComponents/Core concern or are part of the Enum datatypes. Normally I'd say the latter, but we're in a unique situation since there's 3 datatypes that rely on it. HMM! If we do consider them a core concern, I agree that it makes sense to remove that dependency and move the class. Glad to do that for you if you like.

Just thinking out loud, but maybe DataTypes that wish to provide XsltExtensions should define them in their own namespace, and uComponents.XsltExtensions should just be for "global" methods, ie those that don't relate to a datatype? Wouldn't really work in this case since there's multiple datatypes, just thinking for the future.

@tomfulton
tomfulton deleted the feature/enum-helper branch January 23, 2014 20:47
@leekelleher

Copy link
Copy Markdown
Contributor

Thanks Tom, all good (and valid) points!

Okay, let's leave XsltExtensions with a dependency on DataTypes - if I'm correct, I think it is only a soft-dependency binding anyway, e.g. .NET will only use the reference when the method is called.

@leekelleher leekelleher modified the milestones: v6.0.1, v6.1.0 Mar 28, 2014
@leekelleher leekelleher modified the milestones: v6.1.0, v6.0.1 Jun 23, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

3 participants