Example #1
0
        private static IList<object> ToList(object obj)
        {
            var list = new List<object>();

            if (obj == null)
            {
                return list;
            }

            var types = new[]
                            {
                                typeof(string), typeof(ObjectId),
                                typeof(Commit), typeof(TagAnnotation),
                                typeof(Tag), typeof(Branch), typeof(DetachedHead),
                                typeof(Reference), typeof(DirectReference), typeof(SymbolicReference)
                            };

            if (types.Contains(obj.GetType()))
            {
                list.Add(obj);
                return list;
            }

            list.AddRange(((IEnumerable)obj).Cast<object>());
            return list;
        }
        public static bool RequiresSort(this IDomObject node)
        {
            var name = node.NodeName;

            if (string.IsNullOrWhiteSpace(name))
                return false;

            var sortable = new[] { "ITEMGROUP" };
            var result = sortable.Contains(name);
            return result;
        }
Example #3
0
        public ActionResult Download()
        {
            var codeDict = _codeService.Query().ToDictionary(x => x.Id.ToString(), x => x.Label);

            using (var excel = new ExcelPackage())
            {
                var worksheet = excel.Workbook.Worksheets.Add("Agencies");
                worksheet.Cells[1, 1].Value = "Agencies";

                var exclude = new[] {"Codes", "UserId", "User", "IsNew"};
                var props = typeof(Agency).GetProperties()
                                          .Where(x => !exclude.Contains(x.Name))
                                          .ToList();

                //Header
                var row = worksheet.Dimension.End.Row + 1;
                for (var i = 0; i < props.Count; i++)
                {
                    worksheet.Cells[row, i + 1].Value = props[i].Name;
                }

                //Rows
                foreach (var agency in _agencyService.Query().Include(x => x.Codes).ToList())
                {
                    row = worksheet.Dimension.End.Row + 1;
                    for (var i = 0; i < props.Count; i++)
                    {
                        worksheet.Cells[row, i + 1].Value = GetValue(props[i], agency, codeDict);
                    }
                }

                return new FileContentResult(excel.GetAsByteArray(), MediaTypeNames.Application.Octet)
                {
                    FileDownloadName = "Agencies.xlsx",
                };
            }
        }
        public void LocalEnumerable_Contains()
        {
            var names = new[] {"Jack", "Bob"};
            var people = Collection.AsQueryable().Where(x => names.Contains(x.FirstName));

            var queryObject = ((IMongoQueryable)people).GetQueryObject();
            Assert.AreEqual(0, queryObject.Fields.ElementCount);
            Assert.AreEqual(0, queryObject.NumberToLimit);
            Assert.AreEqual(0, queryObject.NumberToSkip);
            Assert.AreEqual(@"{ ""fn"" : { ""$in"" : [""Jack"", ""Bob""] } }", queryObject.Query.ToJson());
        }
		private static bool IsMethodSuitByName(string methodName, MemberInfo m)
		{
			var aliases = new[] { m.Name }.Concat(m.GetCustomAttributes<DynamicExpressionAliasAttribute>().Select(x => x.Name));

			return aliases.Contains(methodName, StringComparer.InvariantCultureIgnoreCase);
		}