コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonProperty"/> class.
 /// </summary>
 public JsonProperty()
 {
     this._type   = JsonPropertyType.Null;
     this._value  = null;
     this._object = null;
     this._list   = null;
 }
コード例 #2
0
 /// <summary>
 /// 创建一个空的JSON对象属性
 /// </summary>
 public JsonProperty()
 {
     mType   = JsonPropertyType.Null;
     mValue  = null;
     mObject = null;
     mList   = null;
 }
コード例 #3
0
ファイル: JsonObject.cs プロジェクト: CocacolaSh/temp
 public virtual void SetValue(Object value)
 {
     if (value is String)
     {
         this._type  = JsonPropertyType.String;
         this._value = (String)value;
     }
     else if (value is Guid)
     {
         this._type  = JsonPropertyType.String;
         this._value = value.ToString();
     }
     else if (value is DateTime)
     {
         this._type  = JsonPropertyType.String;
         this._value = ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss");
     }
     else if (value is List <JsonProperty> )
     {
         this._list = ((List <JsonProperty>)value);
         this._type = JsonPropertyType.Array;
     }
     else if (value is JsonObject)
     {
         this._object = (JsonObject)value;
         this._type   = JsonPropertyType.Object;
     }
     else if (value is bool)
     {
         this._bool = (bool)value;
         this._type = JsonPropertyType.Bool;
     }
     else if (value is Enum)
     {
         this._type   = JsonPropertyType.Number;
         this._number = (Int32)value;
     }
     else if (value == null || value == DBNull.Value)
     {
         this._type = JsonPropertyType.Null;
     }
     else if (value is IEnumerable)
     {
         this._type = JsonPropertyType.Null;
     }
     else
     {
         double d = 0;
         if (double.TryParse(value.ToString(), out d))
         {
             this._number = d;
             this._type   = JsonPropertyType.Number;
         }
         else
         {
             throw new ArgumentException("错误的参数类型!");
         }
     }
 }
コード例 #4
0
 public void Clear()
 {
     Type    = JsonPropertyType.Null;
     _value  = string.Empty;
     _object = null;
     if (_list != null)
     {
         _list.Clear();
         _list = null;
     }
 }
コード例 #5
0
 /// <summary>
 /// 清空属性值,重置为默认值
 /// </summary>
 public void Clear()
 {
     mType   = JsonPropertyType.Null;
     mValue  = String.Empty;
     mObject = null;
     if (mList != null)
     {
         mList.Clear();
         mList = null;
     }
 }
コード例 #6
0
 /// <summary>
 /// Clears this instance.
 /// </summary>
 public void Clear()
 {
     this._type   = JsonPropertyType.Null;
     this._value  = String.Empty;
     this._object = null;
     if (this._list != null)
     {
         this._list.Clear();
         this._list = null;
     }
 }
コード例 #7
0
        /// <summary>
        /// 对于集合类型,添加一个元素
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public JsonProperty Add(Object value)
        {
            if (mType != JsonPropertyType.Null && mType != JsonPropertyType.Array)
            {
                throw new NotSupportedException("Json property not an Array and can not add element!");
            }
            if (mList == null)
            {
                mList = new List <JsonProperty>();
            }
            JsonProperty jp = new JsonProperty(value);

            mList.Add(jp);
            mType = JsonPropertyType.Array;
            return(jp);
        }
コード例 #8
0
        public JsonProperty Add(object value)
        {
            if (Type != JsonPropertyType.Null && Type != JsonPropertyType.Array)
            {
                throw new NotSupportedException("Json属性不是Array类型,无法添加元素!");
            }
            if (_list == null)
            {
                _list = new List <JsonProperty>();
            }
            var jp = new JsonProperty(value);

            _list.Add(jp);
            Type = JsonPropertyType.Array;
            return(jp);
        }
コード例 #9
0
        /// <summary>
        /// Adds the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public JsonProperty Add(Object value)
        {
            if (this._type != JsonPropertyType.Null && this._type != JsonPropertyType.Array)
            {
                throw new NotSupportedException("Json属性不是Array类型,无法添加元素!");
            }
            if (this._list == null)
            {
                this._list = new List <JsonProperty>();
            }
            JsonProperty jp = new JsonProperty(value);

            this._list.Add(jp);
            this._type = JsonPropertyType.Array;
            return(jp);
        }
コード例 #10
0
 public virtual void SetValue(object value)
 {
     if (value is string)
     {
         Type   = JsonPropertyType.String;
         _value = (string)value;
     }
     else if (value is List <JsonProperty> )
     {
         _list = (List <JsonProperty>)value;
         Type  = JsonPropertyType.Array;
     }
     else if (value is JsonObject)
     {
         _object = (JsonObject)value;
         Type    = JsonPropertyType.Object;
     }
     else if (value is bool)
     {
         _bool = (bool)value;
         Type  = JsonPropertyType.Bool;
     }
     else if (value == null)
     {
         Type = JsonPropertyType.Null;
     }
     else
     {
         double d = 0;
         if (double.TryParse(value.ToString(), out d))
         {
             _number = d;
             Type    = JsonPropertyType.Number;
         }
         else
         {
             throw new ArgumentException("错误的参数类型!");
         }
     }
 }
コード例 #11
0
 /// <summary>
 /// Sets the value.
 /// </summary>
 /// <param name="value">The value.</param>
 public virtual void SetValue(Object value)
 {
     if (value is String)
     {
         this._type  = JsonPropertyType.String;
         this._value = (String)value;
     }
     else if (value is List <JsonProperty> )
     {
         this._list = ((List <JsonProperty>)value);
         this._type = JsonPropertyType.Array;
     }
     else if (value is JsonConverter)
     {
         this._object = (JsonConverter)value;
         this._type   = JsonPropertyType.Object;
     }
     else if (value is bool)
     {
         this._bool = (bool)value;
         this._type = JsonPropertyType.Bool;
     }
     else if (value == null)
     {
         this._type = JsonPropertyType.Null;
     }
     else
     {
         double d = 0;
         if (double.TryParse(value.ToString(), out d))
         {
             this._number = d;
             this._type   = JsonPropertyType.Number;
         }
         else
         {
             throw new ArgumentException("错误的参数类型!");
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// 设置属性的值
 /// </summary>
 /// <param name="value"></param>
 public virtual void SetValue(Object value)
 {
     if (value is String)
     {
         mType  = JsonPropertyType.String;
         mValue = (String)value;
     }
     else if (value is List <JsonProperty> )
     {
         mList = ((List <JsonProperty>)value);
         mType = JsonPropertyType.Array;
     }
     else if (value is JsonObject)
     {
         mObject = (JsonObject)value;
         mType   = JsonPropertyType.Object;
     }
     else if (value is bool)
     {
         mBool = (bool)value;
         mType = JsonPropertyType.Bool;
     }
     else if (value == null)
     {
         mType = JsonPropertyType.Null;
     }
     else
     {
         double d;
         if (double.TryParse(value.ToString(), out d))
         {
             mNumber = d;
             mType   = JsonPropertyType.Number;
         }
         else
         {
             throw new ArgumentException("Argument type invalid!");
         }
     }
 }
コード例 #13
0
 public JsonValueWriter(JsonPropertyType propertyType)
 {
     _propertyType = propertyType;
 }
コード例 #14
0
 public JsonArraySerialisor(IEnumerable <string> values, JsonPropertyType propertyType)
 {
     _values       = values;
     _propertyType = propertyType;
 }
コード例 #15
0
 public JsonArraySerialisor(string objectName, IEnumerable <string> values,
                            JsonPropertyType propertyType) : this(values, propertyType)
 {
     _objectName = objectName;
 }
コード例 #16
0
 public JsonArraySerialisor(IEnumerable<string> values, JsonPropertyType propertyType) {
     _values = values;
     _propertyType = propertyType;
 }
コード例 #17
0
 public JsonArraySerialisor(string objectName, IEnumerable<string> values,
     JsonPropertyType propertyType) : this(values, propertyType) {
     _objectName = objectName;
 }
コード例 #18
0
 public JsonValueWriter(JsonPropertyType propertyType) {
     _propertyType = propertyType;
 }