public bool Read() { if (string.IsNullOrEmpty(_number)) { Output.OutputMessage(IS_EMPTY); return(false); } Numeric numer = new Numeric(_number); numer.Init(); if (numer.IsEmpty) { Output.OutputMessage(Output.EMPTY_ARGS); return(false); } IConvertable iconvert = numer as IConvertable; _converter = new Converter(iconvert); if (_converter.Init()) { return(_converter.Read()); } return(false); }
public static HtmlBuilder Td(this HtmlBuilder hb, Column column, IConvertable value) { return(column != null && value != null ? value.Td(hb, column) : hb.Td(action: () => hb .Text(string.Empty))); }
public static HtmlBuilder Td( this HtmlBuilder hb, Context context, Column column, IConvertable value) { return(column != null && value != null ? value.Td(hb : hb, context : context, column : column) : hb.Td( css: TextAlignCss(context: context, column: column), action: () => hb .Text(string.Empty))); }
public static T Convert <T>(this IConvertable <T> self, IConversionContext context) where T : class { if (context.TryGetValue(self, out var res)) { return(res.Cast <T>()); } else { var buildIntention = self.GetBuildIntention(context); context.AddOrThrow(self, buildIntention.Tobuild); buildIntention.Build(); return(buildIntention.Tobuild); } }
internal void RegisterConverter(IConvertable converter) { lock (this.converters) { var convertables = converter.GetType().GetTypeInfo().ImplementedInterfaces.Where(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(IConvertable <,>)); foreach (var convertable in convertables) { var sourceType = convertable.GenericTypeArguments[0]; var targetType = convertable.GenericTypeArguments[1]; this.converters.Add(new Tuple <Type, Type>(sourceType, targetType), () => converter); } } }
public static HtmlBuilder Td( this HtmlBuilder hb, Context context, Column column, IConvertable value, int?tabIndex) { return(column != null && value != null ? value.Td( hb : hb, context : context, column : column, tabIndex : tabIndex) : hb.Td( css: column.CellCss(), action: () => hb .Text(string.Empty))); }
// Generic register function, in case the converter implements // all interfaces. public static void Register <T>(IConvertable <T> converter) { Init(); if (converter is ISelectable <T> ) { m_select_register[typeof(T)] = converter; } if (converter is IInsertable <T> ) { m_insert_register[typeof(T)] = converter; } if (converter is IUpdateable <T> ) { m_update_register[typeof(T)] = converter; } if (converter is IDeleteable <T> ) { m_delete_register[typeof(T)] = converter; } }
public static HtmlBuilder Td( this HtmlBuilder hb, Context context, Column column, IConvertable value, int?tabIndex, ServerScriptModelColumn serverScriptModelColumn = null) { return(column != null && value != null ? value.Td( hb : hb, context : context, column : column, tabIndex : tabIndex, serverScriptModelColumn : serverScriptModelColumn) : hb.Td( css: column.CellCss(serverScriptModelColumn?.ExtendedCellCss), action: () => hb .Text(string.Empty))); }
public AbstractCommandsFactory(IConvertable converter, IPhonebookRepository repository, IPrintable printer) { this.Converter = converter; this.Repository = repository; this.Printer = printer; }
public RegularCommandsFactory(IConvertable converter, IPhonebookRepository repository, IPrintable printer) : base(converter, repository, printer) { }
public Command(IConvertable converter, IPhonebookRepository repository, IPrintable printer) { this.Converter = converter; this.PhonebookRepository = repository; this.Printer = printer; }
/// <summary> /// 将列表转换为数据表 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="list">列表</param> /// <param name="tableName">表名</param> /// <param name="eachPropertyFunc">循环属性函数</param> /// <returns>数据表</returns> public static DataTable ToDataTable <T>(this IList <T> list, string tableName = null, Func <PropertyInfo, bool> eachPropertyFunc = null) { Type type = typeof(T); DataTable dataTable = new DataTable(tableName); PropertyInfo[] propertys = type.GetProperties(); if (propertys.IsNullOrLength0()) { return(dataTable); } List <EntityExcelInfo> excelInfos = new List <EntityExcelInfo>(); // 取出每个属性的特性 foreach (PropertyInfo property in propertys) { if (property.CanRead) { if (eachPropertyFunc != null) { if (!eachPropertyFunc(property)) { continue; } } DisplayAttribute displayAttribute = property.GetCustomAttribute <DisplayAttribute>(); IConvertable convert = null; DisplayConvertAttribute displayConvertAttribute = property.GetCustomAttribute <DisplayConvertAttribute>(); if (displayConvertAttribute != null) { convert = displayConvertAttribute.Convert; } if (displayAttribute == null) { excelInfos.Add(new EntityExcelInfo() { Name = property.Name, Alias = property.Name, Sort = 0, Convert = convert }); continue; } if (displayAttribute.AutoGenerateField) { excelInfos.Add(new EntityExcelInfo() { Name = property.Name, Alias = string.IsNullOrWhiteSpace(displayAttribute.Name) ? property.Name : displayAttribute.Name, Sort = displayAttribute.Order, Convert = convert }); } } } if (excelInfos.IsNullOrCount0()) { return(dataTable); } // 按字段排序 excelInfos.Sort(new EntityExcelComparer()); // 创建Excel列 foreach (EntityExcelInfo item in excelInfos) { dataTable.Columns.Add(item.Alias); } if (list.IsNullOrCount0()) { return(dataTable); } foreach (T item in list) { DataRow row = dataTable.NewRow(); foreach (EntityExcelInfo item2 in excelInfos) { foreach (PropertyInfo property in propertys) { if (property.Name.Equals(item2.Name)) { object value = property.GetValue(item); if (item2.Convert != null) { value = item2.Convert.To(value); } row[item2.Alias] = value; } } } dataTable.Rows.Add(row); } return(dataTable); }
/// <inheritdoc /> public void RegisterConverter(IConvertable converter) { Guard.ArgumentNotNull(converter, nameof(converter)); this.customConversionAttempt.RegisterConverter(converter); }
public Converter(IConvertable convertModule) { this.convertModule = convertModule; }
public CommandChange(IConvertable converter, IPhonebookRepository repository, IPrintable printer) : base(converter, repository, printer) { }
public static string GridText(this IConvertable value, Column column) { return(column != null && value != null ? value.GridText(column) : string.Empty); }
public CommandList(IConvertable converter, IPhonebookRepository repository, IPrintable printer) : base(converter, repository, printer) { }
public static string GridText(this IConvertable value, IContext context, Column column) { return(column != null && value != null ? value.ToString() : string.Empty); }
public Converter(IConvertable iconvert) { _convert = iconvert; }
/// <summary> /// 将列表转换为数据表 /// </summary> /// <typeparam name="T">类型</typeparam> /// <param name="dataTable">数据表</param> /// <param name="eachRowFun">循环每一行的回调</param> /// <returns>列表</returns> public static IList <T> ToList <T>(this DataTable dataTable, Func <T, DataRow, int, bool> eachRowFun = null) { if (dataTable == null) { return(null); } IList <T> list = new List <T>(dataTable.Rows.Count); if (dataTable.Rows.Count == 0) { return(list); } Type type = typeof(T); PropertyInfo[] propertys = type.GetProperties(); if (propertys.IsNullOrLength0()) { return(list); } int rowNumber = 1; foreach (DataRow row in dataTable.Rows) { T instance = (T)type.Assembly.CreateInstance(type.FullName); // 取出每个属性的特性 foreach (PropertyInfo property in propertys) { if (property.CanWrite) { DisplayAttribute displayAttribute = property.GetCustomAttribute <DisplayAttribute>(); IConvertable convert = null; DisplayValueConvertAttribute displayValueConvertAttribute = property.GetCustomAttribute <DisplayValueConvertAttribute>(); if (displayValueConvertAttribute != null) { convert = displayValueConvertAttribute.Convert; } string name = string.IsNullOrWhiteSpace(displayAttribute.Name) ? property.Name : displayAttribute.Name; if (dataTable.Columns.Contains(name)) { object tableValue = row[name]; object value = convert == null ? tableValue : convert.To(tableValue); if (value == null) { continue; } ReflectUtil.SetPropertyValue(property, instance, value); } } } if (eachRowFun != null && !eachRowFun(instance, row, rowNumber)) { return(null); } list.Add(instance); rowNumber++; } return(list); }