Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to get values stored in Scripting.Dictionary instance.

How to get values stored in Scripting.Dictionary instance.

Scheduled Pinned Locked Moved C#
csharptutorialwpfwinformswcf
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Christian Merritt
    wrote on last edited by
    #1

    Hi, I am using a vender-provided COM object in a C# Windows Forms application to extract proprietary data format from an AD attribute. The data is stored in an associative array. The problem I am having is retrieving the items that the object returns as its parameters. For example, upon binding to an AD container object, the object creates an instance of type Scripting.Dictionary within COM object, and exposes this instance as a property called "Parameters." I've tried casting to a ListDictionary, HybridDictionary, you name it. Nothing seems to work except IEnumerator. The problem I'm having is how to retrieve the items for each key in the Scripting.Dictionary collection. I'm able to retrieve the names of the keys, but now I simply want to get the values for each key, called "Items". I've wrapped the Scripting.Dictionary class into a .NET assembly using the TLBIMP libary and included it in my project. Here's a snippet of my code so far: // AD path to bind to string ADsPath = "LDAP://CN=Some List,OU=Distribution Lists,DC=DomainA,DC=CorpA,DC=com"; // instantiate the vender COM object AGQueryClass ag = new AGQueryClass(); // bind to the AD path ag.Set(ADsPath); //cast ag.Parameters to Scripting.Dictionary instance Scripting.DictionaryClass sd = (Scripting.DictionaryClass) ag.Parameters; // get collection enumerator IEnumerator IEn = sd.GetEnumerator(); // array to hold keys Array ary = Array.CreateInstance(typeof(object), sd.Count); IEn.Reset(); IEn.MoveNext(); // populate the array with key names for (int i=0; i

    Richard DeemingR 1 Reply Last reply
    0
    • C Christian Merritt

      Hi, I am using a vender-provided COM object in a C# Windows Forms application to extract proprietary data format from an AD attribute. The data is stored in an associative array. The problem I am having is retrieving the items that the object returns as its parameters. For example, upon binding to an AD container object, the object creates an instance of type Scripting.Dictionary within COM object, and exposes this instance as a property called "Parameters." I've tried casting to a ListDictionary, HybridDictionary, you name it. Nothing seems to work except IEnumerator. The problem I'm having is how to retrieve the items for each key in the Scripting.Dictionary collection. I'm able to retrieve the names of the keys, but now I simply want to get the values for each key, called "Items". I've wrapped the Scripting.Dictionary class into a .NET assembly using the TLBIMP libary and included it in my project. Here's a snippet of my code so far: // AD path to bind to string ADsPath = "LDAP://CN=Some List,OU=Distribution Lists,DC=DomainA,DC=CorpA,DC=com"; // instantiate the vender COM object AGQueryClass ag = new AGQueryClass(); // bind to the AD path ag.Set(ADsPath); //cast ag.Parameters to Scripting.Dictionary instance Scripting.DictionaryClass sd = (Scripting.DictionaryClass) ag.Parameters; // get collection enumerator IEnumerator IEn = sd.GetEnumerator(); // array to hold keys Array ary = Array.CreateInstance(typeof(object), sd.Count); IEn.Reset(); IEn.MoveNext(); // populate the array with key names for (int i=0; i

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Try this:

      using System;
      using System.Collections;
      using System.Collections.Specialized;

      public class ScriptingUtils
      {
      public static IDictionary ConvertDictionary(Scripting.IDictionary dict)
      {
      HybridDictionary ret = new HybridDictionary(dict.Count);

          foreach(object k in dict)
          {
              // Can't pass k as ref, because it's read-only
              object key = k;
              
              // Can't pass a ref to an indexer
              // Use the accessor method instead
              object value = dict.get\_Item(ref key);
              
              ret.Add(key, value);
          }
          
          return ret;
      }
      

      }

      You can then change your code to:

      using System;
      using System.Collections;
      ...
      // AD path to bind to
      string ADsPath = "LDAP://CN=Some List,OU=Distribution Lists,DC=DomainA,DC=CorpA,DC=com";

      // instantiate the vender COM object
      AGQueryClass ag = new AGQueryClass();
      
      // bind to the AD path
      ag.Set(ADsPath);
      
      IDictionary dict = ScriptingUtils.ConvertDictionary(
          (Scripting.IDictionary)ag.Parameters);
      
      object\[\] keys = new object\[dict.Count\];
      object\[\] values = new object\[dict.Count\];
      int index = 0;
      
      foreach(DictionaryEntry entry in dict)
      {
          // Do something with the entry here...
          keys\[index\] = entry.Key;
          values\[index\] = entry.Value;
          index++;
      }
      

      ...


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      C 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Try this:

        using System;
        using System.Collections;
        using System.Collections.Specialized;

        public class ScriptingUtils
        {
        public static IDictionary ConvertDictionary(Scripting.IDictionary dict)
        {
        HybridDictionary ret = new HybridDictionary(dict.Count);

            foreach(object k in dict)
            {
                // Can't pass k as ref, because it's read-only
                object key = k;
                
                // Can't pass a ref to an indexer
                // Use the accessor method instead
                object value = dict.get\_Item(ref key);
                
                ret.Add(key, value);
            }
            
            return ret;
        }
        

        }

        You can then change your code to:

        using System;
        using System.Collections;
        ...
        // AD path to bind to
        string ADsPath = "LDAP://CN=Some List,OU=Distribution Lists,DC=DomainA,DC=CorpA,DC=com";

        // instantiate the vender COM object
        AGQueryClass ag = new AGQueryClass();
        
        // bind to the AD path
        ag.Set(ADsPath);
        
        IDictionary dict = ScriptingUtils.ConvertDictionary(
            (Scripting.IDictionary)ag.Parameters);
        
        object\[\] keys = new object\[dict.Count\];
        object\[\] values = new object\[dict.Count\];
        int index = 0;
        
        foreach(DictionaryEntry entry in dict)
        {
            // Do something with the entry here...
            keys\[index\] = entry.Key;
            values\[index\] = entry.Value;
            index++;
        }
        

        ...


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        C Offline
        C Offline
        Christian Merritt
        wrote on last edited by
        #3

        Yes, that did it! Thank you Richard.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups