protected void AssertCreateType <T>(Type RegType) { TkDebug.Assert(ObjectUtil.IsSubType(typeof(T), RegType), string.Format(ObjectUtil.SysCulture, "注册类型{0}不是参数T类型{1}的子类,无法进行类型转换,请确认", RegType, typeof(T)), this); }
private void AddAdditionObj(string regName, Type type, BasePlugInAttribute attr) { if (ObjectUtil.IsSubType(typeof(EvaluateAdditionType), type)) { EvaluateAdditionType add = CreateInstance <EvaluateAdditionType>(regName); EvaluatorUtil.AddAdditionObj(add.CreateAdditionObject()); } else { string name = type.Name; EvaluatorUtil.AddAdditionObj((name, type)); } }
private static object GetDefaultValue(Type type, object defaultValue, ITkTypeConverter converter, ReadSettings settings) { if (defaultValue != null) { if (ObjectUtil.IsSubType(type, defaultValue.GetType())) { return(defaultValue); } else { try { string value = defaultValue.ToString(); return(converter.ConvertFromString(value, settings)); } catch { return(null); } } } else { if (type.IsEnum) { return(GetFirstEnumValue(type)); } else if (type.IsValueType) { return(ObjectUtil.CreateObject(type)); } else { return(null); } } }