Skip to content

feat: Moved to generics - #3286

Open
Doprez wants to merge 19 commits into
stride3d:masterfrom
Doprez:reduce-casts-in-collections
Open

feat: Moved to generics#3286
Doprez wants to merge 19 commits into
stride3d:masterfrom
Doprez:reduce-casts-in-collections

Conversation

@Doprez

@Doprez Doprez commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Reopening from #2866 as I think this was mostly agreed on but was on hold due to being a breaking change.

PR Details

This PR shows a POC that would reduce the amount of required casts by users. I don't want to merge this but I was curious on what the thoughts would be on something like this as using object causes a ton of casting and required checks to be usable. Ideally I would redo this PR but with the Obsolete attribute. The only variable that gets in the way is CollectionChanged as I dont know what the non-obsolete variable would be called.

I also still need to verify that there wont be weird checks in the GameStudio layers as I assume they may not like generics as much as objects. Works fine.

Related Issue

No related issues. I ran into this today trying to use tracking collections for a modular system I am experimenting with as seen in the code snippet below:

    private void WornItemsChanged(object? sender, TrackingCollectionChangedEventArgs e)
    {
        if (e.Action == NotifyCollectionChangedAction.Add)
        {
            var newItem = e.Item;
            if (e.Item is GameItem item && !item.HasDescriptor<WearableDescriptor>())
            {
                _logger.Error($"Only wearable items can be worn. Item: {item.Name}");

                // Remove the item if it is not wearable
                var key = e.Key as string;
                var oldItem = e.OldItem == null ? null : e.OldItem as GameItem;
                WornItems[key] = oldItem;
            }
        }
    }

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

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