❔ A property is changed even though it shouldn't?
This is driving me absolutely bonkers but something weird is going on.
I'm making a local variable at the beginning to which I assign data from apiListData. I'm making some changes on that local variables, especially that foreach (var x in filtered) which filters data. When I do debug point on that console.writeline apiListData from the beginning which was accessed only is affected even though it shouldn't. And don't mind second local variable, I was doing it only to avoid this weird situation Whole .cs - https://pastebin.com/4pezNHzB
apiListData is just raw data that I'm assigning in Refresh task to keep it for filtering purposes.
Pastebin
using System.Collections.ObjectModel;using System.ComponentModel;us...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
25 Replies
classes are reference types, so
filt
and startFilter
and apiListData
all "point" to the same objectHow do I "copy" it then so it isn't altered by the whole process
there is no standard way to do it
what do you suggest here
without knowing anything about the library you're using i'd look for any support for it in the library first
are you sure you need to make a copy of it and you can't do whatever you're trying to do another way?
I want to keep apiListData untouched somehow
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Are you just correcting code or fixing my problem?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
And the setter is not accessed when that change happens, this is normal too?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yes i was trying to say that
that perhaps through that observable it changed
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
that observable is binded to collectionview but it one-way
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
yes
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Where do I set break point then
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
tebeco#0205
Quoted by
<@!689473681302224947> from #A property is changed even though it shouldn't? (click here)
React with ❌ to remove this embed.
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
but where, I haven't ever used it
that seed thing
I'm going to sleep, cause I'm tired
Will message tomorrow
but you can reply
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I don't have any add loop on lines 836-936 (when I get data from API) but I think I get your point, I'll try later when I get home
Am i doing it wrong again?
I'm populating tmp with lists from apiListData
on that last console.writeline apiListData is affected as before again
which lines were you talking about
What if i make apiListData serialized back to json and deserialize when needed? That should make "a copy". Idk how performant would that be with approx 500 items max, on mobile device
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.