GHA Namespace Variable

I have a .GHA plug-in i’ve been working on. It includes a component with a rather large dictionary structure. I want to make a new component that does a different task on the same dictionary. Rather than having two massive dictionaries in each component class with double the associated memory overhead, I am wondering if there is a way to make it accessible within the components namespace?

After looking online there are some examples on stackoverflow that look of the form:

    namespace plugin_name.
    {
        extern int test = 1;

However, this throws an error without an error message. Any help would be amazing.

If you are distributing both components as part of the same package.
put the dictionary as it’s own class without inhering anything like the following:

namespace plugin_Namespace
{
    class dictionary
    {
        public dictionary()
        {
            //Dictionary data
        }
    }
}

If you are using the same namespace for all the components which is allowed, you can access the dictionary class with the data.
You might have to post your files for a bit more specific help.

Hey Chris thanks for your help. I’ve tried this as I guess I need to put the dictionary into a public variable like you said. Now I get:

Severity Code Description Project File Line Suppression State Suppression State
Error CS0246 The type or namespace name ‘Dictionary<,>’ could not be found (are you missing a using directive or an assembly
   public class dictionary
        {
            public Dictionary<string, List<int>> dictionary_name =
               new Dictionary<string, List<int>>()
               { 
                   //Dictionary Data
               }
        {

Can you first try:

namespace Custom_Component_Namespace
{
    class dictionary
    {
        public static Dictionary<string, List<int>> dictionary_name = new Dictionary<string, List<int>>()
        { 
             //Dictionary Data
        };
    }

    public class Component_1 : GH_Component
    {
    }

    public class Component_2 : GH_Component
    {
    }
}

Hey Chris - Got it working :smiley: How do I call the dictionary from an external class now?

dictionary.dictionary_name[key]
or
class_name.dictionary_name[key]

if you have multiple dictionaries, you can put them all in the same class.

Hey Chris, the error seems to come from when the dictionary is called by the component as it is the first line where the error occurs.

 string name = "";

            if (!data_access.GetData(0, ref name)) { return; }

            List<int> values = dictionary.dictionary_name[name];

can you copy the error message here? or uploading the file would be easiest if it doesn’t contain confidential information.

That’s my issue - there is no error message. I get 5 warnings. The warning messages relate to commented out lines of code.

Are you trying to build it or running it at the moment?
Could you upload a screenshot of the code where you define the dictionary?

Hey Chris,

Turns out it was a bug with Visual Studio. I think due to the length of the dictionary the software was confusing what was and was not commented.

Thank you so much for all your help! :smiley:

If you want to separate the code, you can put each class in it’s own file as long as they are part of the same project and have the same namespace.
Also mark the question as solved/ the answer above as the solution.