コード例 #1
0
        internal static object InternalGetDefaultValue(Type type, string strValue, object defaultValue,
                                                       ReadSettings settings, bool throwException)
        {
            ITkTypeConverter converter = TkTypeDescriptor.GetConverter(type);

            if (throwException)
            {
                TkDebug.AssertNotNull(converter, string.Format(ObjectUtil.SysCulture,
                                                               "无法获取类型{0}的TypeConverter,请确认是否为其配置TypeConverterAttribute",
                                                               type), null);
            }
            else
            {
                if (converter == null)
                {
                    return(GetTypeDefaultValue(type));
                }
            }
            try
            {
                return(strValue == null?InternalGetDefaultValue(type, defaultValue)
                           : converter.ConvertFromString(strValue, settings));
            }
            catch
            {
                return(InternalGetDefaultValue(type, defaultValue));
            }
        }
コード例 #2
0
        public static object GetValue(object sender, Type type, string strValue,
                                      object defaultValue, ReadSettings settings)
        {
            TkDebug.AssertArgumentNull(type, "type", sender);

            ITkTypeConverter converter = TkTypeDescriptor.GetConverter(type);

            AssertTypeConverter(sender, type, converter);
            return(InternalGetValue(type, strValue, defaultValue, settings, converter));
        }
コード例 #3
0
 public ReflectorObjectPropertyInfo(PropertyInfo property,
                                    BaseObjectAttribute attribute, string modelName)
     : base(attribute, modelName)
 {
     fProperty   = property;
     fPascalName = property.Name;
     fCamelName  = char.ToLowerInvariant(fPascalName[0]) + fPascalName.Substring(1);
     Converter   = TkTypeDescriptor.GetConverter(property,
                                                 attribute.GetObjType(property.PropertyType, property.Name));
 }
コード例 #4
0
        public static object GetPropertyObject(object receiver, ReadSettings settings,
                                               ObjectPropertyInfo info, string value, Type objType)
        {
            ITkTypeConverter converter = info.Converter ?? TkTypeDescriptor.GetConverter(objType);

            ObjectUtil.AssertTypeConverter(receiver, objType, converter, info.PropertyName);

            object obj = ObjectUtil.InternalGetValue(objType, value, info.Attribute.DefaultValue,
                                                     settings, converter);

            return(obj);
        }
コード例 #5
0
        public static string ToString(object obj, WriteSettings settings)
        {
            if (obj == null)
            {
                return(string.Empty);
            }

            ITkTypeConverter converter = TkTypeDescriptor.GetConverter(obj.GetType());

            if (converter != null)
            {
                return(converter.ConvertToString(obj, settings));
            }
            else
            {
                return(obj.ToString());
            }
        }