-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix editor can write invalid config options (e.g. D3D9 gfx driver for Linux) #2260
Fix editor can write invalid config options (e.g. D3D9 gfx driver for Linux) #2260
Conversation
I think cloning may be done using reflection, about same way as automatic serialization is done in SerializeUtils: run through all properties that have setters, optionally skip properties with certain attributes (or not?), and copy property values. That might result in a similar effect, but skipping writing and parsing XML doc in memory. If you add Clone method, probably it makes sense to add ICloneable to the list of interfaces this class implements. |
There's a weird note in .net docs to not put ICloneable in public APIs (at the last sentence here). |
Hmm, I see... This sais:
But to think about this, Is not the same true for this Clone method? It does not seem to guarantee that all fields are cloned, does not let choose whether to do shallow or deep copy. Actually, since the current implementation secretly uses xml serialization, the result would probably be a sort of a deep copy, since any referenced sub-objects will be recreated (although this will probably not make a difference for RuntimeSetup class). EDIT: what I mean, maybe it will make more sense to write a generic separate method for cloning like this, which could be called on any similar type, but it will be more dependable on what it does. |
eecba1f
to
92d49cc
Compare
@ivan-mogilko , here is what I did
I think better understanding of what cloning mean will have to be exercised at a later time when solving #601. |
I just want to clarify: since we are adding a method to the public interface, then we must clearly specify what is expected from this method, and this expectation has to be kept in the future (and likely repeated for each similar class, since this is a universal kind of function).
That is true, constructing a new object depends on a use-case then. But property-copying function that you wrote seems fine, and it accepting an object as an argument in line with DeserializeFromXML. |
7cee81f
to
5b4df18
Compare
Oh, I am not certain, no, as I mentioned I think a thorough investigation of Clone is necessary for #601, but I don't want to commit to it at this point, I just want to solve #2206. I will try to hide this inside BuildTargetBase, but keep it public (in Editor project) just for testing. I will look into this later tonight. In general for #601 I expect we will figure that clone can't always make everything the same since some fields are expected to be unique (scriptName adds a sequential number at end or IDs that will get the next available) - or maybe we will have to do this in two steps to keep identifiers unique, since it depends on objects other than itself, so it needs the Editor for the information. But currently this is not something I know enough for all objects, only that for RuntimeSetup specifically a shallow copy is indeed the best approach. |
I recall that there's a "internal" access modifier which makes things be seen only within an assembly, idk if this will help here (are tests located in a separate one?) |
Did as I mentioned and hidden the cloning in BuildTargetBase. Went ahead and squashed around the commits. Previous commits are in fix-editor-config-invalid-bkp branch. |
9516e46
to
e374d53
Compare
- Fix case when writing GraphicsDriver config in acsetup.cfg, check if it's D3D9 and use OpenGL instead. - clone of RuntimeSetup is hidden in BuildTargetBase - TO-DO: when a Clone or Duplicate is decided for AGS.Types objects, move naïve copy from AGS.Editor Utilities
Fix #2206
My approach to cloning the RuntimeSetup may be a bit unusual but it was the only idea I had as I believe assignment in C# will be only a reference. The other approach would be to explicitly copy each field.