Beispiel #1
0
                public override void Process(char c)
                {
                    if (c == '}') // End of Object
                    {
                        _onDone(_curr);
                    }
                    else if (_internState == InternalState.WaitForName)
                    {
                        if (c == '"')
                        {
                            _reader.State = new CaptureStringState(name =>
                            {
                                _reader.State = this;

                                _currSubVal      = new BjSJsonObjectMember();
                                _currSubVal.Name = name;
                                _curr.Add(_currSubVal);

                                _internState = InternalState.WaitForSeperator;
                            });
                        }
                    }
                    else if (_internState == InternalState.WaitForSeperator)
                    {
                        if (c == ':')
                        {
                            _reader.State = new SelectValueState(_reader, this, obj =>
                            {
                                _currSubVal.Value = obj;
                                _reader.State     = this;
                                _internState      = InternalState.WaitForNextOrEnd;
                            });
                        }
                    }
                    else if (_internState == InternalState.WaitForNextOrEnd)
                    {
                        if (c == ',')
                        {
                            _internState = InternalState.WaitForName;
                        }
                    }
                }
Beispiel #2
0
        private static BjSJsonObject ToJsonObject(Type t, object obj)
        {
            BjSJsonObject result = new BjSJsonObject();

            PropertyInfo[] properties = t.GetProperties();
            foreach (PropertyInfo pi in properties)
            {
                if (pi.CanRead && pi.CanWrite)
                {
                    object val  = pi.GetValue(obj, null);
                    object jVal = ToJsonValue(val);
                    if (!(jVal is IncompatibleValue))
                    {
                        result.Add(pi.Name, jVal);
                    }
                }
            }

            return(result);
        }