reflection - Traverse and find all given type instances within complex object graph -
reflection - Traverse and find all given type instances within complex object graph -
(using vb.net 4.0) have object graph complex - has properties, arrays , other collections, subclasses own properties , collections, etc. want traverse entire object graph , find instances of particular type t, perform particular operation on these instances. there bulletproof way perform total traversal of object graph? reflection, seems hard task prone error.
i wondering binary serialization, since seems clone object, no matter how complicated, in robust manner. there way modify technique, such instead of serializing instead returns list of references sub-objects of given type t? pure speculation, i'm open feasible solution.
well figured out method, though isn't best. because object's graph pretty nested & complex, decided rely on binary serialization, since in (limited) experience offers thorough & robust graph traversal. downside binary serialization can impact performance significantly, after benchmarking doesn't appear limiting factor particular situation.
basically, have type t implement iserializable, can handle post-serialization adding class:
protected sub new(byval info system.runtime.serialization.serializationinfo, byval context system.runtime.serialization.streamingcontext)
another way (without implementing iserializable) create post-serialized method "ondeserialized" attribute.
anyways, can set info streamingcontext object, used describe operation want performed on type t instances. basically, serialize parent object, find , serialize sub-objects of type t, can coded perform desired task upon deserialization. going forward, deal serialized objects.
obviously, serialization can have complications, , method won't work situations. pretty inelegant performance-wise too. needed hassle-free & thorough object graph traversal there go.
reflection vb.net-2010 binary-serialization object-graph
Comments
Post a Comment