예제 #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);
 }
예제 #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");
        }
예제 #3
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public Number AsNumber()
 {
     if (mObject is int)
     {
         return new Number((int)mObject);
     }
     else
     {
         if (mObject is double)
         {
             return new Number((double)mObject);
         }
         else
         {
             if (mObject is string)
             {
                 LexBase lex = new LexBase((string)mObject);
                 Number num = lex.ParseNumber();
                 if (num != null)
                 {
                     return num;
                 }
                 else
                 {
                     return new Number(0);
                 }
             }
             else
             {
                 if (mObject == null)
                 {
                     return new Number(0);
                 }
             }
         }
     }
     // convert error
     ThrowVariantConvertError(this, TYPE_INTEGER, TYPE_REAL);
     return null;
 }
예제 #4
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public void AsNumber(Kirikiri.Tjs2.Variant targ)
 {
     if (mObject == null)
     {
         targ.Set(0);
     }
     else
     {
         if (mObject is Number)
         {
             // Integer or Double
             if (mObject is int)
             {
                 targ.Set(((int)mObject));
             }
             else
             {
                 targ.Set(((Number)mObject));
             }
         }
         else
         {
             if (mObject is string)
             {
                 LexBase lex = new LexBase((string)mObject);
                 Number num = lex.ParseNumber();
                 if (num != null)
                 {
                     if (num.IsInt())
                     {
                         targ.Set(((int)num));
                     }
                     else
                     {
                         targ.Set(((Number)num));
                     }
                 }
                 else
                 {
                     targ.Set(0);
                 }
             }
             else
             {
                 // convert error
                 ThrowVariantConvertError(this, TYPE_INTEGER, TYPE_REAL);
             }
         }
     }
 }
예제 #5
0
 /// <exception cref="Kirikiri.Tjs2.VariantException"></exception>
 public int AsInteger()
 {
     if (mObject is int)
     {
         return ((int)mObject);
     }
     else
     {
         if (mObject is double)
         {
             return (int)((double)mObject);
         }
         else
         {
             if (mObject is string)
             {
                 LexBase lex = new LexBase((string)mObject);
                 Number num = lex.ParseNumber();
                 if (num != null)
                 {
                     return num;
                 }
                 else
                 {
                     return 0;
                 }
             }
             else
             {
                 if (mObject == null)
                 {
                     return 0;
                 }
                 else
                 {
                     // bytebuffer or object
                     ThrowVariantConvertError(this, TYPE_INTEGER);
                 }
             }
         }
     }
     return 0;
 }
예제 #6
0
 public bool AsBoolean()
 {
     if (mObject is int)
     {
         return ((int)mObject) == 0 ? false : true;
     }
     else
     {
         if (mObject is double)
         {
             return ((double)mObject) == 0.0 ? false : true;
         }
         else
         {
             if (mObject is string)
             {
                 LexBase lex = new LexBase((string)mObject);
                 Number num = lex.ParseNumber();
                 if (num != null)
                 {
                     return num == 0 ? false : true;
                 }
                 else
                 {
                     return false;
                 }
             }
             else
             {
                 if (mObject is VariantClosure)
                 {
                     VariantClosure v = (VariantClosure)mObject;
                     return (v.mObject != null);
                 }
                 else
                 {
                     if (mObject is ByteBuffer)
                     {
                         return true;
                     }
                     else
                     {
                         if (mObject == null)
                         {
                             return false;
                         }
                         else
                         {
                             return false;
                         }
                     }
                 }
             }
         }
     }
 }
예제 #7
0
 public static Number StringToNumber(string str)
 {
     LexBase lex = new LexBase(str);
     Number num = lex.ParseNumber();
     if (num != null)
     {
         return num;
     }
     else
     {
         return new Number(0);
     }
 }