Friday, January 22, 2010

CF9 GetMemento() that works with inheritance

Here's my take on getMemento() in CF9... (non-recursive)

You might  want to return a duplicate() of properties if you like.

struct function getMemento()
{
  var properties = {};
  
  for (local.md = getMetaData(this);

       structKeyExists(md, "extends");
       md = md.extends)
  {
    if (structKeyExists(md, "properties"))
    {
      for (local.i = 1;

           i <= arrayLen(md.properties);
           i++)
      {
        local.pName = md.properties[i].name;
        local.properties[pName]

          = structKeyExists(variables, pName) ?
            variables[pName] : "";
      }
    }
  }
  
  return properties;
}