Kirikiri.Tjs2.ArrayNI.AssignStructure C# (CSharp) Method

AssignStructure() public method

public AssignStructure ( Dispatch2 dsp, AList stack ) : void
dsp Dispatch2
stack AList
return void
        public virtual void AssignStructure(Dispatch2 dsp, AList<Dispatch2> stack)
        {
            // assign structured data from dsp
            ArrayNI arrayni = (ArrayNI)dsp.GetNativeInstance(ArrayClass.ClassID);
            if (arrayni != null)
            {
                // copy from array
                stack.AddItem(dsp);
                try
                {
                    mItems.Clear();
                    int count = arrayni.mItems.Count;
                    for (int i = 0; i < count; i++)
                    {
                        Variant v = arrayni.mItems[i];
                        if (v.IsObject())
                        {
                            // object
                            Dispatch2 dsp1 = v.AsObject();
                            // determin dsp's object type
                            //DictionaryNI dicni = null;
                            //ArrayNI arrayni1 = null;
                            if (dsp1 != null && dsp1.GetNativeInstance(DictionaryClass.ClassID) != null)
                            {
                                //dicni = (DictionaryNI)ni.mValue;
                                // dictionary
                                bool objrec = false;
                                int scount = stack.Count;
                                for (int j = 0; j < scount; j++)
                                {
                                    Dispatch2 d = stack[j];
                                    if (d == dsp1)
                                    {
                                        // object recursion detected
                                        objrec = true;
                                        break;
                                    }
                                }
                                if (objrec)
                                {
                                    mItems.AddItem(new Variant());
                                }
                                else
                                {
                                    // becomes null
                                    Dispatch2 newobj = TJS.CreateDictionaryObject();
                                    mItems.AddItem(new Variant(newobj, newobj));
                                    DictionaryNI newni;
                                    if ((newni = (DictionaryNI)newobj.GetNativeInstance(DictionaryClass.ClassID)) !=
                                        null)
                                    {
                                        newni.AssignStructure(dsp1, stack);
                                    }
                                }
                            }
                            else
                            {
                                if (dsp1 != null && dsp1.GetNativeInstance(ArrayClass.ClassID) != null)
                                {
                                    // array
                                    bool objrec = false;
                                    int scount = stack.Count;
                                    for (int j = 0; j < scount; j++)
                                    {
                                        Dispatch2 d = stack[j];
                                        if (d == dsp1)
                                        {
                                            // object recursion detected
                                            objrec = true;
                                            break;
                                        }
                                    }
                                    if (objrec)
                                    {
                                        mItems.AddItem(new Variant());
                                    }
                                    else
                                    {
                                        // becomes null
                                        Dispatch2 newobj = TJS.CreateArrayObject();
                                        mItems.AddItem(new Variant(newobj, newobj));
                                        ArrayNI newni;
                                        if ((newni = (ArrayNI)newobj.GetNativeInstance(ArrayClass.ClassID)) != null)
                                        {
                                            newni.AssignStructure(dsp1, stack);
                                        }
                                    }
                                }
                                else
                                {
                                    // other object types
                                    mItems.AddItem(v);
                                }
                            }
                        }
                        else
                        {
                            // others
                            mItems.AddItem(v);
                        }
                    }
                }
                finally
                {
                    stack.Remove(stack.Count - 1);
                }
            }
            else
            {
                throw new TJSException(Error.SpecifyDicOrArray);
            }
        }