C
C#2y ago
MrScautHD

❔ Get all Types that extend from my class Entity

Heyy! I want to get all my Entity Typesm would that possible to get all classes that use Entity?
8 Replies
ZacharyPatten
ZacharyPatten2y ago
Why are you wanting to do that? Can you describe more generally what kind of application you are making and what you are trying to do? From your short description of your scenario you sound like you are looking for "reflection" but you want to avoid reflection in general. there is pretty much always a better option than reflection nowadays
MrScautHD
MrScautHDOP2y ago
I try to get all EnityTypes To listen it up into my Map Editor And add it to my World with the Map Editor
ZacharyPatten
ZacharyPatten2y ago
yeah... we still need a lot more information to really help
MrScautHD
MrScautHDOP2y ago
ok sec
chairclr
chairclr2y ago
A simple solution with reflection would be as follows:
Type[] types = typeof(Entity).Assembly.GetTypes().Where(x =>
!x.IsAbstract &&
x.IsSubclassOf(typeof(Entity))).ToArray();
Type[] types = typeof(Entity).Assembly.GetTypes().Where(x =>
!x.IsAbstract &&
x.IsSubclassOf(typeof(Entity))).ToArray();
although you'd definitely only want to do this once and cache it somewhere
MrScautHD
MrScautHDOP2y ago
thx 🙂 oh and btw if i now want to create a Object with this how can i do that?
chairclr
chairclr2y ago
use the Activator class iirc
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server