Copied to clipboard

Flag this post as spam?

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


  • Tahir 13 posts 73 karma points
    Feb 06, 2017 @ 16:43
    Tahir
    0

    Truly typed objects

    Hi all,

    lets say you have a multiple media picker property called primaryHeaderItems. Now in Umbraco 7.4 and higher in generated file you have something like

    [ImplementPropertyType("primaryHeaderItems")]
            public string PrimaryHeaderItems
            {
                get { return this.GetPropertyValue<string>("primaryHeaderItems"); }
            }
    

    Now in order to get IPhublishedContent, what you have to do is

    private IList<IPublishedContent> GetContentItemsFromCsv(string csv)
            {
                var contents = new List<IPublishedContent>();
                var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    
                if (!string.IsNullOrWhiteSpace(csv))
                {
                    var listOfContents = csv.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse);
                    return umbracoHelper.TypedContent(listOfContents).ToList();
                }
                return contents;
            }
    

    is there any way we can modify the .generate file to get IList

    Thanks

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Feb 06, 2017 @ 16:45
    Kevin Jump
    100

    HI,

    if you also Core Property Value Converters package.

    https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters

    aAnd then generate your models you should get the property returning as a IEnumerable<IPublishedContent> collection.

  • Tahir 13 posts 73 karma points
    Feb 09, 2017 @ 16:33
    Tahir
    0

    Thanks my friend. You saved my life :-)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies