/// <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; }
/// <summary> /// 创建一个空的JSON对象属性 /// </summary> public JsonProperty() { mType = JsonPropertyType.Null; mValue = null; mObject = null; mList = null; }
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("错误的参数类型!"); } } }
public void Clear() { Type = JsonPropertyType.Null; _value = string.Empty; _object = null; if (_list != null) { _list.Clear(); _list = null; } }
/// <summary> /// 清空属性值,重置为默认值 /// </summary> public void Clear() { mType = JsonPropertyType.Null; mValue = String.Empty; mObject = null; if (mList != null) { mList.Clear(); mList = null; } }
/// <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; } }
/// <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); }
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); }
/// <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); }
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("错误的参数类型!"); } } }
/// <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("错误的参数类型!"); } } }
/// <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!"); } } }
public JsonValueWriter(JsonPropertyType propertyType) { _propertyType = propertyType; }
public JsonArraySerialisor(IEnumerable <string> values, JsonPropertyType propertyType) { _values = values; _propertyType = propertyType; }
public JsonArraySerialisor(string objectName, IEnumerable <string> values, JsonPropertyType propertyType) : this(values, propertyType) { _objectName = objectName; }
public JsonArraySerialisor(IEnumerable<string> values, JsonPropertyType propertyType) { _values = values; _propertyType = propertyType; }
public JsonArraySerialisor(string objectName, IEnumerable<string> values, JsonPropertyType propertyType) : this(values, propertyType) { _objectName = objectName; }