private object GetValue(Type type, object value) { if (type.IsPrimitive) { return(GetPrimitiveValue(type, value)); } else if (Nullable.GetUnderlyingType(type) != null) //if we're nullable, id say call the getvalue method again on the underlying type { var t = Nullable.GetUnderlyingType(type); return(GetValue(t, value)); } else if (type == typeof(string)) { return(value.ToString()); } else if (type.IsEnum) { return(ConvertExtensions.ToEnum <XmlEnumAttribute>(value.ToString(), type)); } else if (type == typeof(DateTime)) { return(DateTime.Parse(value.ToString())); } else if (type == typeof(TimeSpan)) { return(ConvertExtensions.ToTimeSpan(value.ToString())); } return(null); }