In a LayerTableEvent callback, I am copying Layer properties from the OldState event property to store for later comparison (and to prevent corruption by accessing the state directly in solveInstance). The call looks like this:
Layer oldState = new Layer();
if (e.OldState != null) oldState.CopyAttributesFrom(e.OldState);
The problem is that the e.OldState.FullPath is “something::hi”, but the copied oldState.FullPath is just “hi”. It looks like it is truncating the FullPath into just the layer name.
Incidentally, I was able to build a workaround for the NewState by storing the string in a static variable, but I ran into another problem, which is that OldState is incorrectly a Name in the FullPath property field.
Layer.CopyAttributesFrom only copies typical attributes from another layer. Thus, properties, such as Layer.ParentLayerId which is used to generate the full path, are not copied. If you need more stuff then what Layer.CopyAttributesFrom copies, you’ll need to do so on your own.
Your welcome to call it what you want. But the same thing happens internally that you’ve observed with Layer.CopyAttributesFrom. If you trying to track the layer object itself, do so by id rather than by name or full path name.
So the OldState property is actually using the same CopyAttributesFrom in the background to generate the properties of OldState? Hm.
Maybe we could improve the CopyAttributesFrom routine? It boggles my mind why a method called “CopyAttributesFrom” would copy incomplete attributes but maintain original property names. Confusing to have a FullPath property that isn’t actually copied but rather gets populated by a name. I guess i would call that a bug, yes.
So in the meantime, I have to maintain a dictionary of layer guids and values that I care about, so I can use the OldState’s layer Guid to look up the previous value? That’s what I’m hearing, and that’s what I’ll do!