Exemplo n.º 1
0
 /// <exception cref="VariantException"></exception>
 /// <exception cref="TjsException"></exception>
 public virtual bool Callback(string name, int flags, Variant value)
 {
     if ((flags & Interface.HIDDENMEMBER) != 0)
     {
         return(true);
     }
     if (mCalled)
     {
         mStream.Write(",\n");
     }
     mCalled = true;
     mStream.Write(mIndentStr);
     mStream.Write("\"");
     mStream.Write(LexBase.EscapeC(name));
     mStream.Write("\" => ");
     if (value.IsObject())
     {
         // object
         VariantClosure clo = value.AsObjectClosure();
         ArrayNI.SaveStructuredDataForObject(clo.SelectObject(), mStack, mStream, mIndentStr
                                             );
     }
     else
     {
         mStream.Write(Utils.VariantToExpressionString(value));
     }
     return(true);
 }
Exemplo n.º 2
0
        /// <exception cref="VariantException"></exception>
        /// <exception cref="TjsException"></exception>
        public static void SaveStructuredDataForObject(Dispatch2 dsp, AList <Dispatch2> stack
                                                       , TextWriteStreamInterface stream, string indentstr)
        {
            // check object recursion
            int count = stack.Count;

            for (int i = 0; i < count; i++)
            {
                Dispatch2 d = stack[i];
                if (d == dsp)
                {
                    // object recursion detected
                    stream.Write("null /* object recursion detected */");
                    return;
                }
            }
            // determin dsp's object type
            DictionaryNI dicni;
            ArrayNI      arrayni;

            if (dsp != null)
            {
                dicni = (DictionaryNI)dsp.GetNativeInstance(DictionaryClass.ClassID);
                if (dicni != null)
                {
                    // dictionary
                    stack.AddItem(dsp);
                    dicni.SaveStructuredData(stack, stream, indentstr);
                    stack.Remove(stack.Count - 1);
                    return;
                }
                else
                {
                    arrayni = (ArrayNI)dsp.GetNativeInstance(ArrayClass.ClassID);
                    if (arrayni != null)
                    {
                        // array
                        stack.AddItem(dsp);
                        arrayni.SaveStructuredData(stack, stream, indentstr);
                        stack.Remove(stack.Count - 1);
                        return;
                    }
                    else
                    {
                        // other objects
                        stream.Write("null /* (object) \"");
                        // stored as a null
                        Variant val = new Variant(dsp, dsp);
                        stream.Write(LexBase.EscapeC(val.AsString()));
                        stream.Write("\" */");
                        return;
                    }
                }
            }
            stream.Write("null");
        }