How to get all keys of vertex or edge?

Dec 17, 2013 at 11:16 AM
In my application" vertex.SetValue("Key1","v1"); vertex.SetValue("Key2","v2"); ... vertex.SetValue("Keyn","vn")". How can I get a list of metadata Key list such as List<string>("Key1","Key2",..."Keyn")?
Dec 17, 2013 at 4:56 PM
Edited Dec 17, 2013 at 5:17 PM
The metadata collection object is private, so there is no easy way to ask for a collection of metadata keys that have been set on a vertex.

If you need a collection of metadata keys that your own application has set, then you presumably know the names of those keys and you could create a method that looks something like the following. (I have not tried compiling this, so it might have typos.)
List<String> GetMetadataKeys(IMetadataProvider vertexOrEdge)
{
    List<String> metadataKeys = new List<String>();

    String[] keysUsedByThisApplication = new String[] {
        "Key1",
        "Key2",
        "KeyN"
        };

    foreach (String keyUsedByThisApplication in keysUsedByThisApplication)
    {
        if ( vertexOrEdge.ContainsKey(keyUsedByThisApplication) )
        {
            metadataKeys.Add(keyUsedByThisApplication);
        }
    }

    return (metadataKeys);
}
This is a bit fragile, because you would have to remember to update keysUsedByThisApplication when you start using a new key.

-- Tony