In LayerTableEvent, Layer.CopyAttributesFrom is incorrectly copying the FullPath property

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.

Am I missing something?

Thanks,
Marc

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.

Hi @marcsyp,

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.

– Dale

Thanks Dale!

That’s fair in terms of the CopyAttributesFrom method, but still doesn’t answer the issue of the OldState not having a proper FullPath – is that a bug?

Marc

Hi @marcsyp,

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.

– Dale

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. :slight_smile:

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!

Cheers,
Marc