redmoss
How to serialize part of an object with a guid but then deserialize later?
So at runtime, I'll populate a list of objects that have a
guid id
and a string name
and a bool isFlagged
. When I serialize, I don't care about the name because it gets created again when the object is instantiated so there's no need to store that data.
But when deserializing, I instantiate the list of objects again, then want to go through each one and, using the guid
s I saved, set the isFlagged
that I had serialized. The problem is, the new instances have new guids
so there's no way to map the deserialized data back to their originals.
How should I approach this problem?8 replies
Additional profiling tools for Visual Studio (or cmdline)?
Two questions really:
1) I'm using the Visual Studio Diagnostic tools to do memory snapshots and look at CPU usage, but one thing I'd really like to do is literally get all the methods in my code listed by the number of times they are called, mainly to review my methods and locate any that are being called way too many times than I expect them to be. I imagine it's quite expensive to track this but I didn't see an obvious way to get this info with the Diag tools
2) What other third-party tools/plugins/etc do you use or would reccomend for finding opportunities for optimizations in my code?
4 replies
Nice ways to partially serialize and deserialize objects?
Say I've got a class like this:
In my program, I might have various instances of these in a List that I refer to. When I serialize this list, it saves
Id
Name
and AttackRating
but these are instanced in the code so if I change the code, the serialization is now out of date for users who try and load the save when the code has moved on. So really, I just want to serialize the Seen
property, because the rest is defined in code by the MonsterFactory
.
However, I'm not sure how I can deserialise a List<Monster>
which was just serialised with the Seen
properties serialised only, if that makes sense. The other values are instantiated by the appropriate MonsterFactory in code. Now, I can use [JsonIgnore]
to serialize just Seen
. However the problem is recreating the list of objects without overwriting the other properties using the MonsterFactory
for the rest.
Basically I want to be able to create my Monster
class again from the factory method, but then deserialize a List<Monster>
from file that only stored Seen
because it's the only property without [JsonIgnore]
. But when I do this, it's going to set all my other properties to null
.
Any thoughts?7 replies
How to refactor two classes that need visibility of each other?
I have two classes,
InputManager
and DisplayManager
. In my current model, InputManager
sometimes needs to write to the display, and DisplayManager
needs to see the current state of input, so they have need of each other.
At the moment I'm handling it like:
So both objects have a reference to each other and can call each's relevant public methods. The problem is of course that I get lots of "potentially null" warnings because I can't (seemingly) pass the displayManager
via inputManager
's constructor because it doesn't exist yet, and vice versa.
I was wondering what the right approach is where I can guarantee non-null references but still have the two have access to each other?7 replies