예제 #1
0
        /// <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);
        }
예제 #2
0
    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);
        }
    }
예제 #3
0
        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);
        }
예제 #4
0
파일: JsonUtils.cs 프로젝트: viola19/JsonMe
        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);
        }
예제 #5
0
    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);
    }
예제 #6
0
        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);
            }
        }