|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
isMethodDefined() function??
I need an isMethod() or isMethodDefined() - or someway to fake it - to find out if a specific method of an object is available or not.
I'm not too keen on using a try/catch to do this as that seems really hacky to me. Any ideas? -D |
|
#2
|
|||
|
|||
|
You can use getMetaData() for a CFC and determine just about anything about the CFC from that. Though I suspect that this would be slower than just using cftry and calling the method to see what happens.
![]()
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
This function might help you
<cffunction name="isMethodDefined" returntype="boolean"> <cfargument name="component" type="any" required="true" /> <cfargument name="name" type="string" required="true" /> <cfset var funct = structfind( getmetadata( arguments.component ), 'functions')> <cfset var i = 1> <cfif isArray( funct ) and arraylen( funct )> <cfloop from="1" to="#arraylen( funct )#" index="i"> <cfif funct[i].name eq arguments.name> <cfreturn true /> </cfif> </cfloop> </cfif> <cfreturn false /> </cffunction> |
|
#4
|
|||
|
|||
|
I didn't think of using metadata like that - although I do agree that it's going to be more instensive than a try/catch - so that's what I've gone with.
Thanks for your suggestions. -D |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > isMethodDefined() function?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|