/// <summary> /// このJSONノードが持つプロパティのうち指定された名前のプロパティを返します. /// 指定された名前のプロパティが存在しない場合は例外をスローします. /// </summary> /// <returns>プロパティ値.</returns> /// <param name="name">プロパティ名.</param> public IJsonObject GetProperty(string name) { IJsonProperty r = Properties.FirstOrDefault((arg) => arg.Name.Equals(name)); if (r == null) { throw new ApplicationException( string.Format("json node has not property \"{0}\".", name)); } return(r.Value); }
public static JsonValue ToJsonValue(IJsonProperty property, object value) { try { if (property.Converter == null) { return(JsonUtils.ToJson(value)); } return(property.Converter.ToJsonValue(property.PropertyInfo.PropertyType, value)); } catch (Exception ex) { throw new ConversionException(property.PropertyInfo, value, ex); } }
public static void SetProperty(object entity, IJsonProperty property, JsonValue value) { var propertyType = property.PropertyInfo.PropertyType; object propertyValue; try { propertyValue = property.Converter == null ? value : property.Converter.FromJsonValue(propertyType, value); } catch (Exception ex) { throw new ConversionException(property.PropertyInfo, value, ex); } PropertySetter.Set(entity, property.PropertyInfo, propertyValue); }
public static void SetProperty(object entity, IJsonProperty property, JsonValue value) { var propertyType = property.PropertyInfo.PropertyType; object propertyValue; try { if (property.Converter == null) { propertyValue = value; if (property.PropertyInfo.PropertyType.IsEnum) { object tempobject = (value as JsonPrimitive).Value; if (tempobject is int) { propertyValue = tempobject; } else { propertyValue = Enum.Parse(property.PropertyInfo.PropertyType, (string)tempobject); } } else if (property.PropertyInfo.PropertyType == typeof(Guid)) { propertyValue = new Guid(value.ToString()); } } else { propertyValue = property.Converter.FromJsonValue(propertyType, value, entity.GetType()); } } catch (Exception ex) { throw new ConversionException(property.PropertyInfo, value, ex); } PropertySetter.Set(entity, property.PropertyInfo, propertyValue); }
public static JsonValue ToJsonValue(IJsonProperty property, object value) { try { if (property.Converter == null) { return JsonUtils.ToJson(value); } return property.Converter.ToJsonValue(property.PropertyInfo.PropertyType, value); } catch (Exception ex) { throw new ConversionException(property.PropertyInfo, value, ex); } }