internal static void SetObjectValue(object receiver, ReadSettings settings, ObjectPropertyInfo info, string value, bool autoTrim) { object obj = GetPropertyObject(receiver, settings, info, value, autoTrim); info.SetValue(receiver, obj); }
public void ReadObjectElement(ObjectElementAttribute attribute, object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData) { DataTable table = serializerData.Convert <DataTable>(); if (table.Rows.Count == 0) { return; } Type objectType = info.ObjectType; IObjectSerializer rowSerializer = ObjectExtension.CreateSerializer("DataRow"); if (attribute.IsMultiple) { IList list = attribute.GetList(receiver, info); foreach (DataRow row in table.Rows) { object subObject = ReadObject(attribute.UseConstructor, settings, row, objectType, receiver, rowSerializer, info.ModelName); list.Add(subObject); } } else { object subObject = ReadObject(attribute.UseConstructor, settings, table.Rows[0], objectType, receiver, rowSerializer, info.ModelName); info.SetValue(receiver, subObject); } }
private object ReadSimpleValue(object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, bool autoTrim) { JsonTextReader jsonReader = reader.Convert <JsonTextReader>(); AssertRead(jsonReader); object value = GetSimpleValue(jsonReader, receiver, settings, info, autoTrim); info.SetValue(receiver, value); return(value); }
internal static object GetPropertyValue(object receiver, Type objectType, ObjectPropertyInfo info) { object value = info.GetValue(receiver); // ObjectUtil.GetValue(info, receiver); if (value == null) { Type type = objectType ?? info.DataType; value = ObjectUtil.CreateObject(type); info.SetValue(receiver, value); } return(value); }
private object ReadComplexValue(object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info) { JsonTextReader jsonReader = reader.Convert <JsonTextReader>(); AssertRead(jsonReader); string strValue = ReadComplexContent(jsonReader); object value = SerializerUtil.GetPropertyObject(receiver, settings, info, strValue, false); info.SetValue(receiver, value); return(value); }
public static void AddElementValue(SimpleElementAttribute attribute, object receiver, ObjectPropertyInfo info, object objValue) { if (attribute.IsMultiple) { IList list = attribute.GetList(receiver, info); list.Add(objValue); } else { info.SetValue(receiver, objValue); } }
public void ReadObjectElement(ObjectElementAttribute attribute, object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData) { JsonTextReader jsonReader = reader.Convert <JsonTextReader>(); Type objectType = info.ObjectType; // 考虑支持多层次Array读取,外层Object可能读取过,所以这里做判断对此进行屏蔽 2019.6.24 if (jsonReader.TokenType != JsonToken.StartArray) { AssertRead(jsonReader); } if (attribute.IsMultiple) { IList list = attribute.GetList(receiver, info); if (attribute.UseJsonObject) { bool useArray = jsonReader.TokenType == JsonToken.StartArray; if (useArray) { while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { break; } object subObject = ReadObject(attribute.UseConstructor, settings, jsonReader, objectType, receiver, info.ModelName); list.Add(subObject); } } else { object subObject = ReadObject(attribute.UseConstructor, settings, jsonReader, objectType, receiver, info.ModelName); list.Add(subObject); } } else { AssertReadState(jsonReader, JsonToken.StartArray, info.PropertyName); while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { break; } object subObject = ReadObject(attribute.UseConstructor, settings, jsonReader, objectType, receiver, info.ModelName); list.Add(subObject); } } } else { AssertReadState(jsonReader, JsonToken.StartObject, info.PropertyName); object subObject = ReadObject(attribute.UseConstructor, settings, jsonReader, objectType, receiver, info.ModelName); info.SetValue(receiver, subObject); } }