コード例 #1
0
 public static object FromJson(Type type, JToken jToken)
 {
     if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
     {
         Type underlyingType = Nullable.GetUnderlyingType(type);
         return(FromJson(underlyingType, jToken));
     }
     else if (type == typeof(RestDateTime))
     {
         return(new RestDateTime(RestDatabase.DateTimeFromTimestamp((long)jToken)));
     }
     else if (jToken is JObject && type.IsSubclassOf(typeof(RestObject)))
     {
         RestObject obj = (RestObject)Activator.CreateInstance(type);
         obj.FromJson((JObject)jToken);
         return(obj);
     }
     else if (type.IsEnum)
     {
         return(Enum.ToObject(type, (int)jToken));
     }
     else
     {
         object obj = jToken.ToObject(type);
         return(obj);
     }
 }
コード例 #2
0
        public void ReadXml(XmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.ReadStartElement();
                return;
            }

            string longString = reader.ReadInnerXml();

            if (String.IsNullOrWhiteSpace(longString) == false)
            {
                long seconds = XmlConvert.ToInt64(longString);
                Value = RestDatabase.DateTimeFromTimestamp(seconds);
            }
        }
コード例 #3
0
        public void Populate(Dictionary <string, object> record)
        {
            Dictionary <string, string> map = GetTableMap();

            Type type = GetType();

            string column;
            object value;
            Type   propertyType;

            foreach (string key in map.Keys)
            {
                PropertyInfo property = type.GetProperty(key);
                column = map[key];
                if (!record.ContainsKey(column))
                {
                    continue;
                }

                value        = record[column];
                propertyType = property.PropertyType;
                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = Nullable.GetUnderlyingType(propertyType);
                }
                if (propertyType == typeof(RestDateTime))
                {
                    value = new RestDateTime(RestDatabase.DateTimeFromTimestamp((long)value));
                }
                else if (propertyType.IsEnum)
                {
                    value = Enum.Parse(propertyType, value.ToString());
                }

                property.SetValue(this, value);
            }
        }