none
how to get the parent array of a clr object RRS feed

  • Question

  • i have an alterneting background markup extension in wpf which decides whether to do a light background or a dark background based of the index of the object inside of it's array,if the number is even then it returns light if it's odd it returns dark

    now my problem is that i can only get the object from the array without the array itself,
    but in order to call Array.IndexOf  i need both the array and one of it's objects

    so my question is , how can i get the array from the object that i have,
    is it possible to get a list of objects that have referances to this object, because then,
    one of them must be the array that holds this object?

    maybe it is possible with Reflection or something with GC?

    thanks
    Sunday, February 21, 2010 1:09 PM

Answers

  • It seems you are going the wrong way about this. First off, there is no easy way for an object to find out if it's referenced by an array, not even with reflection.

    Here are some solutions you can explore:

    1. Use a control which supports alternating template rendering. Then the control keeps track of the index it renderes.
    2. Introduce a global counter in your control, and check and increase it when you decide on what color to use.
    3. Introduce an index property to your object which you set before binding and rendering the array
    4. Introduce a property which references the parent array to your array object
    I would try and stay away from 3 and 4 as they would clutter your code and make it more complex than necessary.

    Hope this leads you in the right direction. Since you posted no code it's hard to give exact advise.

    Regards,
    Mikael Svenson

    Search Enthusiast - MOSS MCTS
    http://techmikael.blogspot.com/ - http://www.comperio.no/
    • Marked as answer by eryang Monday, March 1, 2010 2:11 AM
    Sunday, February 21, 2010 2:30 PM

All replies

  • It seems you are going the wrong way about this. First off, there is no easy way for an object to find out if it's referenced by an array, not even with reflection.

    Here are some solutions you can explore:

    1. Use a control which supports alternating template rendering. Then the control keeps track of the index it renderes.
    2. Introduce a global counter in your control, and check and increase it when you decide on what color to use.
    3. Introduce an index property to your object which you set before binding and rendering the array
    4. Introduce a property which references the parent array to your array object
    I would try and stay away from 3 and 4 as they would clutter your code and make it more complex than necessary.

    Hope this leads you in the right direction. Since you posted no code it's hard to give exact advise.

    Regards,
    Mikael Svenson

    Search Enthusiast - MOSS MCTS
    http://techmikael.blogspot.com/ - http://www.comperio.no/
    • Marked as answer by eryang Monday, March 1, 2010 2:11 AM
    Sunday, February 21, 2010 2:30 PM
  • Hi igalk474,

    I'm writing to check the issue status, Does Mikael's help? Please feel free to let us know if you have any concern.


    Sincerely,
    Eric
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, February 25, 2010 1:40 AM
  • the listbox supports alternating template so i used it,
    he helped a lot

    thanks
    Tuesday, March 9, 2010 4:21 PM