-
Notifications
You must be signed in to change notification settings - Fork 40
Added generic value support for generators #169
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
Added generic value support for generators #169
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds support for setting generic and managed-reference values on SerializedProperty by using a reflective setter for paths not covered by built-in property types.
- Introduced
SetValueReflectiveto walk a property path, handle arrays/lists, and set field values via reflection - Extended the original
SetValueto handleSerializedPropertyType.ManagedReferenceandSerializedPropertyType.Generic - Ensures changes are applied via
Update/ApplyModifiedPropertiesin the reflective path
Comments suppressed due to low confidence (2)
Scripts/Editor/Extensions/SerializedPropertyExtensions.cs:32
- [nitpick] The parameter name
propis inconsistent with other extension methods that useserializedProperty. Consider renaming it for consistency (e.g.,serializedProperty).
public static void SetValueReflective(this SerializedProperty prop, object value)
Scripts/Editor/Extensions/SerializedPropertyExtensions.cs:34
- The new reflective setter logic covers nested arrays and fields but lacks dedicated unit tests. Consider adding tests for common and edge-case property paths.
object root = prop.serializedObject.targetObject;
| string[] parts = prop.propertyPath | ||
| .Replace(".Array.data[", "[") | ||
| .Split('.'); |
Copilot
AI
May 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing the propertyPath using hard-coded replace/split logic can be brittle. Consider extracting the path parsing into a helper or adding comments to clarify the expected formats.
| string[] parts = prop.propertyPath | |
| .Replace(".Array.data[", "[") | |
| .Split('.'); | |
| string[] parts = ParsePropertyPath(prop.propertyPath); |
| prop.serializedObject.Update(); | ||
| prop.serializedObject.ApplyModifiedProperties(); |
Copilot
AI
May 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Calling Update() and ApplyModifiedProperties() inside the reflective setter may lead to repeated serialization passes when setting multiple properties. It might be more efficient to push these calls to the caller.
| prop.serializedObject.Update(); | |
| prop.serializedObject.ApplyModifiedProperties(); | |
| // Note: The caller is responsible for calling `Update()` and `ApplyModifiedProperties()` | |
| // on the `SerializedObject` to apply changes and update the serialized state. |
| } | ||
| public static void SetValue(this SerializedProperty serializedProperty, object value) | ||
|
|
Copilot
AI
May 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Public extension methods should have XML doc comments. Please add a summary and parameter descriptions for SetValueReflective.
| /// <summary> | |
| /// Sets the value of a serialized property reflectively by traversing its property path. | |
| /// </summary> | |
| /// <param name="prop">The serialized property whose value is to be set.</param> | |
| /// <param name="value">The new value to assign to the property.</param> |
No description provided.