Introspecting non-instanced Classes

Is it possible to use Introspection on classes that do not have instanced objects yet? I’d like to iterate over the classes of a project and get information using introspection. So far I used introspection only on objects and so I wonder if it is possible to get information without doing that.

You can use GetTypeInfo operator to get a Introspection.TypeInfo object. This doesn’t let you iterate over all classes, but it does let you avoid having to create an instance of the class in question.

Thanks for the answer, Joe. But I need to now the name of the class, right? Is there another way of getting a list of the classes in a project? I mean without writing a list that keeps track of them :wink:

There isn’t.

If you could live with a non-automated way of achieving this, you could export your project to XML and then scan it for tags.

I made my first IDE script a couple weeks ago, it was quite a challenge but it saved me from making an external XML processor. The script crawls over the whole project, collecting Window names and then generates code in a couple methods that will create a window with pushbuttons to show each window.

I had a hard time figuring how to identify when an item is a Window. In my case I lucked out because PropertyValue(“MyWindow.Super”) is “Window” and I don’t use intermediary Window subclasses. Anyways, fiddling with that code I came up with a crumby way to identify classes. Basically, try to change the Super, if its changeable then you have a class. Is there a better way?

Also, this is in an IDE Script which you’d need to run periodically. I’ve yet to try Build Scripts, maybe this can be put in there so the generated code is always up to date. The other problem is this script doesn’t run very fast. It might be quicker for a large project to use the XML processing route. Or can this be sped up? There’s so much I don’t understand about IDE scripting :slight_smile:

[code] dim curFullName, curPartName, curType, foundClasses(), oldSuper As String, i As integer

dim stack() As String = Sublocations("").Split(ChrB(9)) //get root
while stack.ubound >= 0

curFullName = stack(stack.ubound)    //get last name in stack
curPartName = NthField(curFullName, ".", CountFields(curFullName, "."))
stack.remove(stack.ubound)          //and remove from stack

oldSuper = PropertyValue(curPartName + ".Super")        //save original super

PropertyValue(curPartName + ".Super") = "some_manky_id" //try to change it

curType = PropertyValue(curPartName + ".Super")         //read back super

if curType = "some_manky_id" then                    //store if super is settable
  PropertyValue(curPartName + ".Super") = oldSuper   //and restore original
  foundClasses.Append curPartName
elseif curType = "" then              //recurse on folders, type = ""
  dim sa() As String = Sublocations(curFullName).Split(ChrB(9))
  for i = 0 to sa.ubound
    stack.append curFullName + "." + sa(i)
  next
end

wend

Print "classes found: " + Join(foundClasses, ", ")

//now generate code in some target method
[/code]

No, not really ;). In this case I’ll use a an array in which I store the needed information.

@Will Shank I need this functionality in a compiled project, so I unfortunately I cannot use an IDE script.

I think his point was that you would automate the creation of the list. The reason there isn’t a way to get a list of classes automagically is that the linker really, really wants to be able to strip out unused classes. GetTypeInfo acts as a root that ensures the class survives dead code stripping.

Out of curiosity, what’s the use case? automatic deserialization?

I wrote a module a while back to ‘pickle’ an object’s state to disk.
I got pretty far but found that not every member could be introspected…
The method is recursive, you pass an object and it traverses the object to retrieve property states.
Pickle

Yeah generic pickle / restore is unlikely to work using just introspection.
Aaron & I tried to write such a thing when introspection first came out & found that you can get a long way - but not entirely there.

[quote=46071:@Joe Ranieri]
Out of curiosity, what’s the use case? automatic deserialization?[/quote]

Working on a simple ORM. Done a lot of that with Python. Really miss the metaclasses there.