Skip to content

Comments

Feature: Inspector (PropertyGrid Expansion)#502

Draft
Bamboy wants to merge 32 commits intords1983:masterfrom
Bamboy:inspector
Draft

Feature: Inspector (PropertyGrid Expansion)#502
Bamboy wants to merge 32 commits intords1983:masterfrom
Bamboy:inspector

Conversation

@Bamboy
Copy link
Contributor

@Bamboy Bamboy commented Feb 18, 2026

  • This PR vastly expands the capabilities of PropertyGrid, Record, and related types to allow anonymous inspection of any C# object type. Reflection is required.

  • This will effectively allow Myra users to have a simple universal runtime debugging tool.

  • This PR adds one new lib dependency Generic.Math which is needed for netstandard2.0. This package requires Reflection.Emit & codegen. Targeting Net7 or above would remove this dependency req because we could use built-in math interfaces instead.

I am opening this PR as a draft so that @rds1983 can review progress, because so much new code is being added.

IMPLEMENTED:

Property Editing:

  • Various property-type testing in new sample project: Myra.Samples.Inspector.
  • PropertyEditor base class encapsulates a Record/MethodInfo and a Widget, as well as provides a means for selecting and creating a Widget for a given Record. Users are intended to be able to extend PropertyEditor to be able to provide drawer-widgets for their custom types. Just declare your extending class type with the below attribute and reflection will handle the rest during initialization...
  • PropertyEditorAttribute registers a PropertyEditor type to one or more Type that the editor can support. Open-generic editor types are supported (in which case the system will attempt to create a generic class of the specified type). If a PropertyEditor does not have this attribute, the system ignores it. The system can be initialized with a custom collection of assemblies to scan for editor-types (possibly excluding Myra's assembly, this is untested). Manual user initialization of PropertyEditor types is not required, and by default the system will try to scan the entire AppDomains' loaded assemblies if it detects the database is null, potentially slow.

Numerics:

  • NumericPropertyEditor<T> supports editing all built-in numeric types. It will spawn a SpinButton<T> widget according to the type of MethodInfo to avoid data-rounding loss by using only float. If the type in MethodInfo is byte or sbyte, the data is converted to ushort or short respectively. (avoids lack of arithmetic operators)
  • The backend for generic-numeric types will throw helpful exceptions if an invalid type is provided during static type initialization.
  • BREAKING CHANGE: SpinButton was refactored from using float to become SpinButton<T>, where T is a numeric type. I did this to fix prior overflow exceptions, and to fix floating point rounding errors. SpinButton<float> should still mostly work like before.

BUGS (as of writing):

  • SpinButton's "DecimalPlaces" and "FixedNumberSize" properties no longer work like they did before in regard to string output. (It was changed to use System.Globalization.NumberFormatInfo for type compatibility)
  • CollectionPropertyEditor (or was it CollectionEditor?) crashes if the collection type is string, with an Activator error.
  • It is unclear in the UI when a BooleanPropertyEditor is marked as Read-Only.
  • Enums and a few others are not working at all. Interface editor-types are kind of working, if I recall.
  • PropertyGrid's "Custom" Funcs are in various states of operation.
  • Properties that update while an object is selected will not visually update values.
  • MyraPad cannot edit SpinButton's properties
  • Exclude new dependency from project if target framework >= .Net7

EVENTUALLY:

  • Add a system for attributes which will directly modify how the property is displayed.
  • Add a way to order properties "by declaration".
  • Support anonymous object nesting.
  • (Low priority) Static properties inspector? :v

Ensure MyraPad still functions:

  • for new SpinButton generic-type format. (Reading + writing XML)
  • for changes that were made to PropertyGrid.

Cleanup:

  • Clean up class names and namespaces for their use-intention.
  • Review public/internal API access.

If/when this is merged into master, it should probably be a major version increment due to breaking API changes in SpinButton.

Bamboy added 30 commits January 31, 2026 07:02
#Conflicts:
#	src/Myra/Graphics2D/UI/Properties/AttachedPropertyRecord.cs
#	src/Myra/Graphics2D/UI/Properties/Record.cs
…elper intermediate class, PropertyGrid bypass of byte and sbyte types due to lacking math ops
…ding XML now parses "SpinButton" "GenericTypeArg" into a constructed generic type.
…lper, and MyraPad now accepts either type format. Fixed MyraPad codegen, saving, and loading for generic types. MyraPad now displays the generic type arg on the left pane.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant