예제 #1
0
        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);
        }
예제 #2
0
 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)));
 }
예제 #3
0
 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)));
 }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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);
                }
            }
        }
예제 #6
0
 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)));
 }
예제 #7
0
 // 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)
 {
 }
예제 #11
0
 public Command(IConvertable converter, IPhonebookRepository repository, IPrintable printer)
 {
     this.Converter = converter;
     this.PhonebookRepository = repository;
     this.Printer = printer;
 }
예제 #12
0
        /// <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);
        }
예제 #14
0
 public AbstractCommandsFactory(IConvertable converter, IPhonebookRepository repository, IPrintable printer)
 {
     this.Converter  = converter;
     this.Repository = repository;
     this.Printer    = printer;
 }
예제 #15
0
 public RegularCommandsFactory(IConvertable converter, IPhonebookRepository repository, IPrintable printer) : base(converter, repository, printer)
 {
 }
예제 #16
0
파일: Converter.cs 프로젝트: FMI-VT/API
 public Converter(IConvertable convertModule)
 {
     this.convertModule = convertModule;
 }
 public CommandChange(IConvertable converter, IPhonebookRepository repository, IPrintable printer)
     : base(converter, repository, printer)
 {
 }
예제 #18
0
 public static string GridText(this IConvertable value, Column column)
 {
     return(column != null && value != null
         ? value.GridText(column)
         : string.Empty);
 }
예제 #19
0
 public Command(IConvertable converter, IPhonebookRepository repository, IPrintable printer)
 {
     this.Converter           = converter;
     this.PhonebookRepository = repository;
     this.Printer             = printer;
 }
 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);
 }
예제 #22
0
 public Converter(IConvertable iconvert)
 {
     _convert = iconvert;
 }
예제 #23
0
        /// <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);
        }