Getting the type of another nested class from the same "parent" class

Viewed 104

I'm attempting to make a namespace for the first time while learning programming. I am hoping there is a way around the problem I've run into that isn't particularly messy, but essentially I have a class object that keeps two dictionaries of two nested class objects. I need to be able to pass the Dictionary of NestedClassA to NestedClassB or to allow NestedClassB to access it in some way... Here is an example of what I'm trying to do:

namespace MyFirstNamespace 
{
    public class BossClass 
    {
        public Dictionary<int, NestedClassA> DictionaryA = new Dictionary<int, NestedClassA>();
        public Dictionary<int, NestedClassB> DictionaryB = new Dictionary<int, NestedClassB>();

        public class NestedClassA { ...arbitrary class definition... }

        public class NestedClassB 
        {
            public Dictionary<int, NestedClassA> PassedDictionary;

            public NestedClassB() { }

            public NestedClassB(Dictionary<int, NestedClassA> tempDic))
            {
                PassedDictionary = tempDic;
            }
        }


        public BossClass() { ... arbitrary constructor ... }

        ...arbitrary dictionary population methods...

        function void CreateAClassBInstance()
        {
            DictionaryB[n] = new NestedClassB(n, DictionaryA);
        }
    }
}

My problem seems to be that I can't typecast "NestedClassA" within "NestedClassB" because it doesn't recognize the type. Is it possible to access the "NestedClassA" type within B? Nothing I've tried has worked. Do I have to pass the instance of "BossClass" so I can reference type by "Dictionary<int, MyFirstNamespace.BossClassInstance.NestedClassA>"?

Any help would be appreciated. To be clear, I want a REFERENCE variable passed to NestedClassB of a Dictionary of all NestedClassA members so they can be manipulated by NestedClassB. It can't be a clone. I know this seems like ridiculous implementation, but it seems the most effective, if it's possible, for what I'm trying to do.

EDIT: maybe I shouldn't be nesting them at all, but it would make them much easier to serialize, which is why I really wanted to do it this way.

(EDIT - fixed typo where I forgot to insert "public" before constructors.)

2 Answers
Related