Skip to main content
October 7, 2010
Question

.NET CreateObject - How to call CollectionBase.Count on derived class

  • October 7, 2010
  • 1 reply
  • 700 views

I am using an assembly that has an class like:

[SerializableAttribute]
public class MetaDataDataCollection : CollectionBase
I have an instance of this class (retrieved via another method) but I cannot seem to call the Count method on this class or the List method (I just need the contents of this class).  Any pointers on how I can get the information stored in the CollectionBase?

The CollectionBase List method is documented here: http://msdn.microsoft.com/en-us/library/system.collections.collectionbase.list.aspx  It returns an IList.

Code:
function WriteEventMetadataTree(eventMetadata)
{
     WriteOutput("<table>");
     _WriteEventMetadataTree(eventMetadata, 2);
     WriteOutput("</table>");
}
function _WriteEventMetadataTree(eventMetadata, depth)
{
     for(i = 1; i lte ArrayLen(eventMetadata); i = i + 1)
     {
          metadata = eventMetadata;
          WriteOutput("<tr>");
          WriteOutput("<td>");
          for(j = 1; j lte depth; j = j + 1)
          {
               WriteOutput(" ");
          }
          WriteOutput("</td><td>");
          WriteOutput(metadata.Get_Name());
          WriteOutput("</td>");
          WriteOutput("</tr>");
          
          metadataChildren = metadata.Get_Children(); // <-- This method returns a
MetaDataDataCollection object
                                _WriteEventMetadataTree(metadataChildren.Get_List(), depth + 2);
     }
}

...
<cfset a = WriteEventMetadataTree(eventMetadata) />

Result:
The Get_List method was not found.
Either there are no methods with the specified method name and argument types or the Get_List method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity.

The error occurred in C:\inetpub\wwwroot\test.cfm: line 195
Called from C:\inetpub\wwwroot\test.cfm: line 175
Called from C:\inetpub\wwwroot\test.cfm: line 200

193 :           
194 :           metadataChildren = metadata.Get_Children();
195 :           _WriteEventMetadataTree(metadataChildren.Get_List(), depth + 2);
196 :      }
197 : }




This topic has been closed for replies.

1 reply

Inspiring
October 9, 2010
metadataChildren.Get_List()

It do not see a call to CollectionBase.Count in the code. The error seems to be coming from CollectionBase.List. The API says that property is "protected".  So you cannot access it.  Try using Get_Count() instead.

October 9, 2010

For whatever reason I was trying to call metadata.Get_Count() instead of metadataChildren.GetCount() when I tested it earlier.  Thanks for the help!

Inspiring
October 9, 2010

Ahh, glad you figured it out!

-Leigh