+ Reply to Thread
Results 1 to 5 of 5

Thread: Is there a way to iterate the keys of an ESObject in C#?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    23
    Thanks
    2
    Thanked 1 Time in 1 Post

    Is there a way to iterate the keys of an ESObject in C#?

    I would like to iterate the keys of an ESObject and then get each value based on the keys.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    23
    Thanks
    2
    Thanked 1 Time in 1 Post
    What I think might work is a foreach() on the EsObject, which I'm guessing returns an EsObjectDataHolder instance in the loop. Looks like I can get the Name (key) from that, then get the value, as well.

    It would be nice to have even one sentence in the API docs about what/where/why for EsObjectDataHolder. Total shot in the dark, here.

    *fingers crossed*

  3. #3
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,209
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    I'll have to research this and get back to you. I know how to do it for Java; see the PluginIteratingOverEsObject code example's plugin.
    Last edited by tcarr; 08-20-2012 at 01:33 PM.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  4. #4
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,209
    Thanks
    80
    Thanked 1,086 Times in 1,075 Posts
    The full source code for EsObjectDataHolder is found in apis/client/c_sharp/unity/src/api (or similar path for Generic C#).

    This should work for you. Look at the source code for EsObject for more specific examples, such as toString and deepClone.
    C# Code:
     
    	foreach( EsObjectDataHolder holder in esob) {
    		// name of the variable is holder.Name
    		// datatype of the variable is holder.getDataType() which is an enum.  
    		// use the datatype to use the correct getter for the value
    	}
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  5. #5
    Junior Member
    Join Date
    Jun 2012
    Posts
    23
    Thanks
    2
    Thanked 1 Time in 1 Post
    Thanks for the pointer!

    Actually, what I proposed in my previous post worked. Doing a foreach( EsObjectDataHolder entry in myContainer ) {} gave me each entry, where I could use entry.Name to get the "key" and entry.GetIntegerValue() or whatever for the value.

    Cheers!

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts