Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nathan 67 posts 146 karma points
    Oct 20, 2014 @ 09:29
    Nathan
    1

    nuPickers: Add attributes to EnumDataSource

    Hi,

    I'm using nuPicker Property Editor to create a CheckBoxList property from an EnumDataSource. Installed the plugin using NuGet. I need an extra attribute for this data source like "Url". How can I add an attribute considering the code is running from a DLL source?

    This is the generated source file for the EnumDataSourceAttribute class that cannot be modified:

    #region Assembly uComponents.nuPickers.dll, v1.2.1.0
    #endregion
    
    using System;
    
    namespace nuPickers.Shared.EnumDataSource
    {
        public class EnumDataSourceAttribute : Attribute
        {
            public EnumDataSourceAttribute();
    
            public bool Enabled { get; set; }
            public string Key { get; set; }
            public string Label { get; set; }
        }
    }
    

    This is my enum:

    public enum SomeEnum
    {
            [EnumDataSource(Key = "0", Label = "Option1")]
            Enum1,
            [EnumDataSource(Key = "1", Label = "Option2")]
            Enum2,
            [EnumDataSource(Key = "2", Label = "Option3")]
            Enum3, 
    }
    

    I need an extra attribute like:

     [EnumDataSource(Key = "0", Label = "Option1", Url = "/media/image.png")]
     Enum1
    

    How can I do this?

    Dan

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 20, 2014 @ 17:52
    Hendy Racher
    0

    Hi Dan,

    The EnumDataSource attribute only supports a Key, Label and an Enabled flag, but could you create a custom attribute for the url property eg. EnumUrlAttribute ?

    public enum SomeEnum
    {
      [EnumDataSource(Key = "0", Label = "Option 1")]
      [EnumUrl("/some/url")]
      Enum1
    }
    

    Where do you need to use the Url property ?

    I did have a helper method to get values out of attributes applied to an enum - I can dig this out if it's of any use ?

    Hendy

  • Nathan 67 posts 146 karma points
    Oct 20, 2014 @ 18:26
    Nathan
    0

    Hi Hendy,

    I need a CheckBoxList Property in BO to select specific options to current page. Every option should have associated values like title (label value), id (key) and Iconurl, so I could use them in a foreach to render with markup in View based on what option is checked. It would be nice to get the values from attributes applied to enums. So if Option1 is checked in BO, I get the key, Url and label attributes values from Option1? How?

    Thanks,

    Dan

Please Sign in or register to post replies

Write your reply to:

Draft