ColdFusion Component MetaData

I recently needed to get the list of functions from a component that I was building. This is helpful especially if you want to loop through the list of functions and execute all of them. Now, this is possible by listing the functions in a variable in a component, but that's not very scalable because every time I add or remove a function, I have to subsequently add or remove that function from the list. So, here is how you dynamically get the list of functions from a component:

<!--- Instantiate the component. CMS --->
<cfset obj = CreateObject("component","com.test.ExpressComponent") />

<!--- Get the metadata. CMS --->
<cfset md = getMetaData(obj) />

<!--- Now loop through the variables. CMS --->
<cfset mdfunc = md.functions />

<!--- Here I dump the info. But it can be processed in whatever manner. CMS --->
<cfloop from="1" to="#ArrayLen(mdfunc)#" index="k">
   <p><cfdump var="#mdfunc[k]#" /></p>
</cfloop>

The getMetaData() function returns a nicely formatted structure of various information about the component. Here is a dump of it:

cfdump of getMetaData() result.

Lot's of valuable information about the component.

Comments
Contact Chris SchofieldBlogCFC was created by Raymond Camden. This blog is running version 5.9.001.