I thought of that, and realized that IsStruct() returns true when passed a component, so it was being passed to the recursive call to my function. I fixed it by adding IsObject() to the same line that checks for values that aren't structures.

            <cfif not IsStruct(arguments.struct[prop]) OR IsObject(arguments.struct[prop])>

This works like a charm, even for arrays. Is there a universal way to find out what type some variable is? As in, is there a GetMetaData() that will work on anything, returning "string", "numeric", "date", "productDAO", etc? Or is this the job of a UDF?

Here's my final function if anyone's interested :) Incidentally, the problem this function addresses is described here: http://forta.com/blog/index.cfm?mode=e&entry=1564

    <cffunction name="structNormalize" returnType="struct" output="false" access="public"
        hint="Format a structure for use in AMF data transfer by normalizing the case of all keys.">
        <cfargument name="struct" type="struct" required="true" hint="Struct to Normalize" />
        <cfargument name="case" type="string" required="false" default="upper" hint="The case to use: upper or lower" />
        <cfset var retStruct = structNew() />
        <!--- This function will loop over a structure and rebuild it using array notation to specify
              the desired case for all keys. If there are any substructures, the function will
              call itself recursively. --->
        <cfloop collection="#arguments.struct#" item="prop">
            <cfif not IsStruct(arguments.struct[prop]) OR IsObject(arguments.struct[prop])>
                <cfif arguments.case EQ "upper">
                    <cfset retStruct['#UCase(prop)#'] = arguments.struct[prop] />
                <cfelse>
                    <cfset retStruct['#LCase(prop)#'] = arguments.struct[prop] />
                </cfif>
            <cfelse>
                <cfif arguments.case EQ "upper">
                    <cfset retStruct['#UCase(prop)#'] = structNormalize(arguments.struct[prop]) />
                <cfelse>
                    <cfset retStruct['#LCase(prop)#'] = structNormalize(arguments.struct[prop]) />
                </cfif>
            </cfif>
        </cfloop>
        <cfreturn retStruct />
    </cffunction>

On 6/2/05, Sean Corfield <[EMAIL PROTECTED]> wrote:
On 6/2/05, Ken Dunnington <[EMAIL PROTECTED]> wrote:
>          <cfset var retStruct = structNew() />

Well, you're turning your components into structs. Regardless of
whether a component or a struct comes in, you always return a struct.



--
In the future, everyone will be Hitler for 15 minutes. -- James Lileks ----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to [email protected] with the words 'unsubscribe cfcdev' as the subject of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting (www.cfxhosting.com).

CFCDev is supported by New Atlanta, makers of BlueDragon
http://www.newatlanta.com/products/bluedragon/index.cfm

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to