简体   繁体   English

如何在Pharo中获得* all *类?

[英]How to get *all* classes in Pharo?

Conundrum... tried Smalltalk allClasses and TBehaviour in Kernel-Traits , among others, seems to be missing from the list. 难题...尝试了Smalltalk allClasses中的Kernel-Traits Smalltalk allClassesTBehaviour ,似乎从列表中丢失了。 Interestingly enough it is a Trait not a Class ...? 有趣的是,这是Trait而不是Class ...? there seem to be corresponding allTraits and allBehaviors . 似乎有对应的allTraits allBehaviors

Any others we should know about when trying to get everything? 我们在尝试获得一切时应该了解的其他任何信息吗? Or is there some other method to get everything? 还是有其他方法来获取所有内容?

您需要执行:

Smalltalk allClassesAndTraits.

Note: I thought that reflection was described in some Pharo book but I don't see it in any, so can't direct you for further reading. 注意:我以为在Pharo的一本书中已经描述了反射,但是我看不到它,因此无法指导您进一步阅读。 🤔 🤔

Classes are Objects 类是对象

You can always use reflection on Pharo objects, which might give you a bit more insight into what you are actually looking for. 您始终可以在Pharo对象上使用反射,这可以使您对实际要查找的内容有更多的了解。

Any class is also an object, an any object understands message allSubclasses (or withAllSubclasses ) that will give you... the subclasses. 任何类也是一个对象,任何对象都可以理解消息allSubclasses (或withAllSubclasses ),这将为您提供...子类。

Object willAllSubclasses

Note that the above will give you also the "class-side" classes (which are metaclass instances for each class), because they are objects too; 请注意,以上内容还将为您提供“类方”类(它们是每个类的元类实例),因为它们也是对象。 so 所以

Smalltalk allClasses asSet =¹ (ProtoObject withAllSubclasses \ Class allSubclasses) asSet
"or"
Smalltalk allClasses asSet = (ProtoObject withAllSubclasses \ Metaclass allInstances) asSet

Traits are not Classes 特质不是阶级

Trait is a class, but TBehavior is not; Trait是一类,但TBehavior不是。 instead it is an instance of Trait . 相反,它是Trait一个实例

So you can say 所以你可以说

Trait allSubclasses. "an OrderedCollection()"
Trait allInstances. "{... TBehavior. TClass. ...}"

¹ SMarkCompilerTargetClass is some special snowflake. SMarkCompilerTargetClass是一些特殊的雪花。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM