Copied to clipboard

Flag this post as spam?

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


  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 20, 2010 @ 01:33
    Chris Houston
    0

    Temporary properties on an in memory Umbraco document.

    Hi All,

    I have some current code that currently creates a list of Umbraco document objects, what I would like to do it to set a flag on some of these objects before they are added to the list so that I can access that flag later in my code.

    I do not want to update the actual documents, this is just on a per-request basis.

                var resources = new List<Document>();
                while (sqlReader.Read())
                {
                    var resourceItem = new Document(sqlReader.GetInt("id"));
    
                    resources.Add(resourceItem);
                }

    You can see from this code snippet currently I have a data set with a list of ID's and I am cycling through that list grabbing the document and adding it to the resource List.

    I am trying to add a "viewed" flag to this document ( which is also in the sqlReader data. )

    This code is already quite deeply embedded in a live solution so a complete re-write in the timescale I have (2 days) is out of the question!

    I hope someone can help :)

    Cheers,

    Chris

  • Neil Campbell 58 posts 182 karma points
    Jul 20, 2010 @ 01:51
    Neil Campbell
    1

    Hey Chris,

    You wont be able to add another property to the actual document object, without modifying the Document class in the Umbraco source.

    You could possibly change the List<T> data structure to a Dictionary<TKey, TValue>, and store the flag in the second position. Maybe not ideal, but could possibly help with what you are trying to do.

    Hope this helps.

    Cheers,
    Neil

  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 20, 2010 @ 02:00
    Chris Houston
    0

    Hi Neil,

    Hope you are doing well down under?

    I was wondering if the way to do it would be to create a new object that inherits from a document but with an additional parameter or am I just tired as it's 1am over here.

    Cheers,

    Chris

  • Neil Campbell 58 posts 182 karma points
    Jul 20, 2010 @ 02:11
    Neil Campbell
    0

    Yep i'm doing well as usual :)
    Actually yes, that could work! I would give that a try.

    Cheers,
    Neil

     

  • Aaron Powell 1708 posts 3044 karma points c-trib
    Jul 20, 2010 @ 05:30
    Aaron Powell
    1

    Sounds like someone is trying to duck type C# :P

    What I'd do is create a class which inherits from Document and IDictionary<string, object> so that you can have it work like a key/ value store. Then you can push in as many properties which only exist as in-memory representations on the instance

  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 20, 2010 @ 11:15
    Chris Houston
    0

    Hi Slace,

    Thanks for your reply, that's basically where I had got to in my thought process at 1am last night ;-)

    I'll give it a go now and we'll see how it goes :)

    Cheers,

    Chris

     

  • Chris Houston 533 posts 977 karma points MVP admin c-trib
    Jul 20, 2010 @ 15:35
    Chris Houston
    0

    So my final solution was as mentioned earlier, I inherited the document object and added two additional properties to my new object, it works like a charm, thanks both for replying to the post.

    Chris

  • 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