Example #1
0
        public ManualDynamicQueryCore(Func <QueryRequest, QueryDescription, CancellationToken, Task <DEnumerableCount <T> > > execute)
        {
            this.Execute = execute ?? throw new ArgumentNullException(nameof(execute));

            this.StaticColumns = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Fields)
                                 .Select((e, i) => new ColumnDescriptionFactory(i, e.MemberInfo, null)).ToArray();
        }
Example #2
0
        protected virtual ColumnDescriptionFactory[] InitializeColumns()
        {
            var result = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Fields)
                         .Select((e, i) => new ColumnDescriptionFactory(i, e.MemberInfo, null)).ToArray();

            return(result);
        }
 public void Complete(IEqualityComparerResolver resolver, PropertyInfo pi)
 {
     Properties = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Typed | MemberOptions.Getter)
                  .ToDictionary(a => a.Name, a => new PropertyComparer <T>((PropertyInfo)a.MemberInfo, a.Getter)
     {
         Comparer = resolver.GetEqualityComparer(((PropertyInfo)a.MemberInfo).PropertyType, ((PropertyInfo)a.MemberInfo))
     });;
 }
Example #4
0
        public AutoDynamicQueryCore(IQueryable <T> query)
        {
            this.Query = query;

            metas = DynamicQueryCore.QueryMetadata(Query);

            StaticColumns = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Fields)
                            .Select((e, i) => new ColumnDescriptionFactory(i, e.MemberInfo, metas[e.MemberInfo.Name])).ToArray();
        }
Example #5
0
        public EntityStructuralEqualityComparer(IEqualityComparerResolver resolver)
        {
            Properties = MemberEntryFactory.GenerateList <T>(MemberOptions.Properties | MemberOptions.Typed | MemberOptions.Getter)
                         .Where(p => !((PropertyInfo)p.MemberInfo).HasAttribute <HiddenPropertyAttribute>())
                         .ToDictionary(a => a.Name, a => new PropertyComparer((PropertyInfo)a.MemberInfo, a.Getter)
            {
                Comparer = resolver.GetEqualityComparer(((PropertyInfo)a.MemberInfo).PropertyType, ((PropertyInfo)a.MemberInfo))
            });

            Mixins = !typeof(Entity).IsAssignableFrom(typeof(T)) ? null :
                     MixinDeclarations.GetMixinDeclarations(typeof(T)).ToDictionary(t => t, t => resolver.GetEqualityComparer(t, null));
        }
        public static DataTable ToDataTable <T>(this IEnumerable <T> collection)
        {
            DataTable table = new DataTable();

            List <MemberEntry <T> > members = MemberEntryFactory.GenerateList <T>();

            table.Columns.AddRange(members.Select(m => new DataColumn(m.Name, m.MemberInfo.ReturningType())).ToArray());
            foreach (var e in collection)
            {
                table.Rows.Add(members.Select(m => m.Getter(e)).ToArray());
            }
            return(table);
        }
        static void WritePlainExcel <T>(IEnumerable <T> results, Stream stream)
        {
            stream.WriteAllBytes(Template);

            if (results == null)
            {
                throw new ApplicationException(ExcelMessage.ThereAreNoResultsToWrite.NiceToString());
            }

            var members = MemberEntryFactory.GenerateList <T>(MemberOptions.Fields | MemberOptions.Properties | MemberOptions.Typed | MemberOptions.Getter);
            var formats = members.ToDictionary(a => a.Name, a => a.MemberInfo.GetCustomAttribute <FormatAttribute>()?.Format);

            using (SpreadsheetDocument document = SpreadsheetDocument.Open(stream, true))
            {
                document.PackageProperties.Creator        = "";
                document.PackageProperties.LastModifiedBy = "";

                WorkbookPart workbookPart = document.WorkbookPart;

                WorksheetPart worksheetPart = document.GetWorksheetPartById("rId1");

                worksheetPart.Worksheet = new Worksheet();

                worksheetPart.Worksheet.Append(new Columns(members.Select((c, i) => new spreadsheet.Column()
                {
                    Min         = (uint)i + 1,
                    Max         = (uint)i + 1,
                    Width       = GetColumnWidth(c.MemberInfo.ReturningType()),
                    BestFit     = true,
                    CustomWidth = true
                }).ToArray()));

                worksheetPart.Worksheet.Append(new Sequence <Row>()
                {
                    (from c in members
                     select CellBuilder.Cell(c.Name, TemplateCells.Header)).ToRow(),

                    from r in results
                    select(from c in members
                           let template = formats.TryGetC(c.Name) == "d" ? TemplateCells.Date : CellBuilder.GetTemplateCell(c.MemberInfo.ReturningType())
                                          select CellBuilder.Cell(c.Getter(r), template)).ToRow()
                }.ToSheetData());

                workbookPart.Workbook.Save();
                document.Close();
            }
        }
        public static string[,] ToStringTable <T>(this IEnumerable <T> collection)
        {
            List <MemberEntry <T> > members = MemberEntryFactory.GenerateList <T>();

            string[,] result = new string[members.Count, collection.Count() + 1];

            for (int i = 0; i < members.Count; i++)
            {
                result[i, 0] = members[i].Name;
            }

            int j = 1;

            foreach (var item in collection)
            {
                for (int i = 0; i < members.Count; i++)
                {
                    result[i, j] = members[i].Getter(item)?.ToString() ?? "";
                }
                j++;
            }

            return(result);
        }