public PagedData <ShopWenTi> GetData(QueryInfo queryInfo, string shopID, string Ncontent, int?wtType, string UserID) { if (UserID.IsNullOrEmpty()) { return(GetSession().Linq <ShopWenTi>() .WhereIf(p => p._Shop.Name.Contains(shopID), shopID.IsNotNullAndEmpty()) .WhereIf(p => p.NContent.Contains(Ncontent), Ncontent.IsNotNullAndEmpty()) .WhereIf(p => p.wtType == wtType.ToString().ToEnum <WenTiType>(), wtType != null) .Page(queryInfo)); } else { List <PinFen> ListPinFen = this.GetSession().Linq <PinFen>().Where(u => u._user.ID == Convert.ToInt64(UserID)).ToList(); List <ShopWenTi> ListShopWenTi = new List <ShopWenTi>(); //ListShopWenTi=this.GetAll().ToList(); foreach (var PinFen in ListPinFen) { IEnumerable <ShopWenTi> ShopWenTi = this.GetSession().Linq <ShopWenTi>().Where(u => u._Shop.ID == PinFen._shop.ID); foreach (var WenTi in ShopWenTi) { ListShopWenTi.Add(WenTi); } } ListShopWenTi = ListShopWenTi.WhereIf(p => p._Shop.Name.Contains(shopID), shopID.IsNotNullAndEmpty()).ToList(); ListShopWenTi = ListShopWenTi.WhereIf(p => p.NContent.Contains(Ncontent), Ncontent.IsNotNullAndEmpty()).ToList(); ListShopWenTi = ListShopWenTi.WhereIf(p => p.wtType == wtType.ToString().ToEnum <WenTiType>(), wtType != null).ToList(); return(ListShopWenTi.Page(queryInfo)); } }
public void WhereIfTest_IEnumerable() { List<int> source = new List<int> { 1, 2, 3, 4, 5, 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, false).ToList(), source); List<int> actual = new List<int> { 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, true).ToList(), actual); }
public void WhereIfTest() { string _name = string.Empty; var _finded = PersonList.WhereIf <Person>(!string.IsNullOrEmpty(_name), c => c.Name.Contains(_name)); Assert.AreEqual(3, _finded.Count()); _name = "yanzhiwei"; _finded = PersonList.WhereIf <Person>(!string.IsNullOrEmpty(_name), c => c.Name.Contains(_name)); Assert.AreEqual(2, _finded.Count()); }
public void WhereIfTest_IEnumerable() { List <int> source = new List <int> { 1, 2, 3, 4, 5, 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, false).ToList(), source); List <int> actual = new List <int> { 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, true).ToList(), actual); }
public void WhereIfTest_IQueryable() { IQueryable <int> source = new List <int> { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable(); Assert.Equal(source.WhereIf(m => m > 5, false).ToList(), source.ToList()); List <int> actual = new List <int> { 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, true).ToList(), actual); }
public PagedResultDto <CustomerForUserPageDto> GetCustomersForUserByList(SearchCustomerForUserInput input) { List <CustomerInfo> cacheList = _customerManage.GetCacheCustomerForUserByList(); cacheList.WhereIf(input.startDate.HasValue, m => m.ApplicationDate >= input.startDate) .WhereIf(input.endDate.HasValue, m => m.ApplicationDate <= input.endDate) .WhereIf(!string.IsNullOrEmpty(input.Area), m => m.Area.StartsWith(input.Area)) .WhereIf(input.maxAge.HasValue, m => m.Age <= input.maxAge) .WhereIf(input.minAge.HasValue, m => m.Age >= input.minAge) .WhereIf(input.maxScore.HasValue, m => m.SesameScore <= input.maxScore) .WhereIf(input.minScore.HasValue, m => m.SesameScore >= input.minScore); var count = cacheList.Count(); var cList = cacheList.Skip(input.SkipCount).Take(input.MaxResultCount).ToList(); var dtoList = cList.MapTo <List <CustomerForUserPageDto> >(); var userId = "," + AbpSession.GetUserId().ToString() + ","; Parallel.ForEach(dtoList, m => { var ids = "," + m.BuyUserIds; if (ids.IndexOf(userId) != -1) { m.ShowForUserStatus = CustomerStatus.C.ToString(); } }); return(new PagedResultDto <CustomerForUserPageDto>(count, dtoList)); }
static void Main(string[] args) { //Set Person person = new Person().Set(p => { p.FirstName = "John"; p.LastName = "Doe"; p.Address = "Groningen, Netherlands"; p.DateOfBirth = new DateTime(1993, 3, 29); }); Console.WriteLine(person); //WhereIf var items = new List<string>() { "aa", "ab", "ba", "bb" }; var subItems = items.WhereIf(false, i => i.StartsWith("a")).ToList(); //Random var numbers = Enumerable.Range(0, 100); var number = numbers.Random(); var randomSelection = numbers.RandomSelection(10).ToList(); //Age Console.WriteLine(person.DateOfBirth.GetAge()); //Parse enum Console.WriteLine("Monday".ParseEnum<DayOfWeek>()); //Enumerable null or empty Console.WriteLine(new List<string>() { "Duco" }.IsNullOrEmpty()); //Join Console.WriteLine(randomSelection.Join(", ")); Console.ReadKey(); }
public async Task <List <AuktionModel> > ListAuktionsAsync(bool includeClosed = false) { List <AuktionModel> list = await _repository.ListAuktionsAsync(); return(list.WhereIf(!includeClosed, a => !a.IsClosed()) .OrderByDescending(a => a.StartDatum) .ToList()); }
public void WhereIfTestNullCheck() { List <Object> list = null; // ReSharper disable once AssignNullToNotNullAttribute // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action test = () => list.WhereIf(true, x => true); test.ShouldThrow <ArgumentNullException>(); }
public void WhereIfTest() { var list = new List <String>(); var actual = list.WhereIf(true, x => true); Assert.Empty(actual); actual = list.WhereIf(true, x => false); Assert.Empty(actual); actual = list.WhereIf(false, x => true); Assert.Empty(actual); list = Extensions.GetRandomStrings(); actual = list.WhereIf(true, x => true); Assert.Equal(list.Count, actual.Count()); actual = list.WhereIf(true, x => false); Assert.Empty(actual); actual = list.WhereIf(false, x => true); Assert.Same(list, actual); }
public void WhereIfTest1() { var list = new List <String>(); var actual = list.WhereIf(true, (x, i) => true); Assert.Equal(0, actual.Count()); actual = list.WhereIf(true, (x, i) => false); Assert.Equal(0, actual.Count()); actual = list.WhereIf(false, (x, i) => true); Assert.Equal(0, actual.Count()); list = RandomValueEx.GetRandomStrings(); actual = list.WhereIf(true, (x, i) => true); Assert.Equal(list.Count, actual.Count()); actual = list.WhereIf(true, (x, i) => false); Assert.Equal(0, actual.Count()); actual = list.WhereIf(false, (x, i) => true); Assert.Same(list, actual); }
static void Main(string[] args) { var array = new List <Int32>() { 1, 2, 3, 4 }; var condition = false; // change it to see different outputs array .WhereIf <Int32>(condition, x => x % 2 == 0) // predicate will be applied only if condition TRUE .WhereIf <Int32>(!condition, x => x % 3 == 0) // predicate will be applied only if condition FALSE .ToList() // don't call ToList() multiple times in the real world scenario .ForEach(x => Console.WriteLine(x)); }
public void WhereIf_Test() { var list1 = new List <string>(); list1.Add("1"); list1.Add("100"); list1.Add("200"); var v1 = list1.WhereIf(true, x => x == "100" || x == "200"); Assert.Equal(2, v1.Count()); var v2 = list1.WhereIf(false, x => x == "1"); Assert.Equal(3, v2.Count()); var v3 = list1.WhereIf(true, (x, y) => x == "1" && y == 0); Assert.Single(v3); var v4 = list1.WhereIf(false, (x, y) => x == "100" || x == "101" && y > 0); Assert.Equal(3, v4.Count()); }
static void Main(string[] args) { //Set Person person = new Person().Set(p => { p.FirstName = "John"; p.LastName = "Doe"; p.Address = "Groningen, Netherlands"; p.DateOfBirth = new DateTime(1993, 3, 29); }); Console.WriteLine(person); //WhereIf var items = new List <string>() { "aa", "ab", "ba", "bb" }; var subItems = items.WhereIf(false, i => i.StartsWith("a")).ToList(); //Random var numbers = Enumerable.Range(0, 100); var number = numbers.Random(); var randomSelection = numbers.RandomSelection(10).ToList(); //Age Console.WriteLine(person.DateOfBirth.GetAge()); //Parse enum Console.WriteLine("Monday".ParseEnum <DayOfWeek>()); //Enumerable null or empty Console.WriteLine(new List <string>() { "Duco" }.IsNullOrEmpty()); //Join Console.WriteLine(randomSelection.Join(", ")); Console.ReadKey(); }
public async Task <IActionResult> Statistics(StatisticsFilterModel filter) { string myId = _userManager.GetUserId(User); List <AuktionBudViewModel> allAuktions = await _service.ListAuktionBudsAsync(true); List <AuktionBudViewModel> filteredAuktions = allAuktions .WhereIf(!filter.ShowMine, a => a.SkapadAv != myId) .WhereIf(!filter.ShowOthers, a => a.SkapadAv == myId) .Where(a => a.SlutDatum.Year == filter.TimeYear && a.SlutDatum.Month == (int)filter.TimeMonth) .ToList(); var model = new StatisticsViewModel { Filter = filter, Auktions = filteredAuktions }; return(View(model)); }
public async Task <IEnumerable <JobResponse> > Jobs(JobSearchRequest request) { GroupMatcher <JobKey> matcher = GroupMatcher <JobKey> .AnyGroup(); if (!string.IsNullOrWhiteSpace(request.Group)) { matcher = GroupMatcher <JobKey> .GroupEquals(request.Group.Trim()); } IReadOnlyCollection <JobKey> jobKeys = await _scheduler.GetJobKeys(matcher); // 根据分组查询条件 获取所有JobKey List <JobResponse> items = new List <JobResponse>(); foreach (JobKey key in jobKeys) { // 过滤掉邮件通知配置job,NLog日志文件清除Job if (string.Equals(key.Name, EmailJobKeys.NameKey, StringComparison.InvariantCultureIgnoreCase) || string.Equals(key.Name, NLogJobKey.NameKey, StringComparison.InvariantCultureIgnoreCase)) { continue; } IJobDetail job = await _scheduler.GetJobDetail(key); if (job == null) { continue; } JobResponse item = new JobResponse { Name = job.Key.Name, Group = job.Key.Group, TriggerState = TriggerState.Complete, HttpMethod = job.JobDataMap.GetHttpMethod(), RequestUrl = job.JobDataMap.GetRequestUrl(), TriggerType = job.JobDataMap.GetTriggerType(), Interval = job.JobDataMap.GetInterval(), IntervalType = job.JobDataMap.GetIntervalType(), RepeatCount = job.JobDataMap.GetRepeatCount(), Cron = job.JobDataMap.GetCron(), RequestBody = job.JobDataMap.GetRequestBody(), Description = job.Description, CreateTime = job.JobDataMap.GetCreateTime(), StartTime = job.JobDataMap.GetStartTime(), EndTime = job.JobDataMap.GetEndTime(), LastException = job.JobDataMap.GetLastException() }; IReadOnlyCollection <ITrigger> triggers = await _scheduler.GetTriggersOfJob(key); ITrigger trigger = triggers.FirstOrDefault(); // 获取当前job关联的第一个 trigger if (trigger != null) { TriggerState triggerState = await _scheduler.GetTriggerState(trigger.Key); // trigger 状态 /****计算时间差***/ DateTime?prevFire = trigger.GetPreviousFireTimeUtc()?.LocalDateTime; DateTime?nextFire = trigger.GetNextFireTimeUtc()?.LocalDateTime; TimeSpan span = TimeSpan.FromSeconds(0); if (prevFire.HasValue && nextFire.HasValue) { span = (nextFire.Value - prevFire.Value); } item.TriggerState = triggerState; item.FirePlan = $"{span.Days}天{span.Hours}小时{span.Minutes}分{span.Seconds}秒"; // 执行频率 item.PrevFireTime = prevFire; item.NextFireTime = nextFire; } ; items.Add(item); } return(items.WhereIf(!string.IsNullOrWhiteSpace(request.Name), x => x.Name.Contains(request.Name.Trim())).OrderByDescending(x => x.CreateTime)); }
public void WhereIfTest_IQueryable() { IQueryable<int> source = new List<int> { 1, 2, 3, 4, 5, 6, 7 }.AsQueryable(); Assert.Equal(source.WhereIf(m => m > 5, false).ToList(), source.ToList()); List<int> actual = new List<int> { 6, 7 }; Assert.Equal(source.WhereIf(m => m > 5, true).ToList(), actual); }
public async Task <string> CheckForSpecificPrice(CheckSpecificPriceInputDto input) { string str; Customer customer; Address address; decimal num1; bool flag; bool flag1; bool flag2; if (input.ProductId <= 0 || input.ForCustomerId <= 0) { str = ""; } else { Product async = await this._productRepository.GetAsync((long)input.ProductId); Product product = async; IRepository <ProductSpecificPrice, long> repository = this._specificPriceRepository; List <ProductSpecificPrice> allListAsync = await repository.GetAllListAsync((ProductSpecificPrice x) => x.ProductId == product.Id); List <ProductSpecificPrice> productSpecificPrices = allListAsync; bool flag3 = false; if (productSpecificPrices.Any <ProductSpecificPrice>()) { List <string> strs = new List <string>(); string empty = string.Empty; List <string> upchargeForUsersOrganizationUnits = new List <string>(); string empty1 = string.Empty; if (input.ForCustomerId <= 0) { customer = null; } else { Customer async1 = await this._customerRepository.GetAsync((long)input.ForCustomerId); customer = async1; } Customer customer1 = customer; if (input.ForCustomerAddressId <= 0) { address = null; } else { Address address1 = await this._addressRepository.GetAsync((long)input.ForCustomerAddressId); address = address1; } Address address2 = address; int countryId = 0; List <long> nums = new List <long>(); if (address2 != null) { countryId = address2.CountryId; } if (customer1 != null && customer1.UserId.HasValue) { FuelWerx.Authorization.Users.UserManager userManager = this._userManager; User userByIdAsync = await userManager.GetUserByIdAsync(customer1.UserId.Value); List <Abp.Organizations.OrganizationUnit> organizationUnitsAsync = await this._userManager.GetOrganizationUnitsAsync(userByIdAsync); nums = ( from ou in organizationUnitsAsync select ou.Id).ToList <long>(); strs = await this._organizationUnitAppService.GetDiscountForUsersOrganizationUnits(customer1.Id); if (strs.Any <string>()) { empty = strs[0]; } upchargeForUsersOrganizationUnits = await this._organizationUnitAppService.GetUpchargeForUsersOrganizationUnits(customer1.Id); if (upchargeForUsersOrganizationUnits.Any <string>()) { empty1 = upchargeForUsersOrganizationUnits[0]; } if (nums.Any <long>()) { customer1 = null; flag3 = true; } } string[] strArrays = new string[0]; if (!string.IsNullOrEmpty(input.ProductOptionIds)) { string productOptionIds = input.ProductOptionIds; productOptionIds.Split(new char[] { ',' }); } IEnumerable <ProductSpecificPrice> productSpecificPrices1 = productSpecificPrices.WhereIf <ProductSpecificPrice>(input.Quantity > 0, (ProductSpecificPrice p) => { int?startingAtQuantity = p.StartingAtQuantity; int quantity = input.Quantity; if (startingAtQuantity.GetValueOrDefault() > quantity) { return(false); } return(startingAtQuantity.HasValue); }).Where <ProductSpecificPrice>((ProductSpecificPrice p) => { if (p.ForCurrency == input.ForCurrency) { return(true); } return(p.ForCurrency == null); }).WhereIf <ProductSpecificPrice>(customer1 != null, (ProductSpecificPrice p) => { long?forCustomerId = p.ForCustomerId; long id = customer1.Id; if (forCustomerId.GetValueOrDefault() != id) { return(false); } return(forCustomerId.HasValue); }).Where <ProductSpecificPrice>((ProductSpecificPrice p) => { int?forCountryId = p.ForCountryId; int num = countryId; if ((forCountryId.GetValueOrDefault() == num ? forCountryId.HasValue : false)) { return(true); } forCountryId = p.ForCountryId; return(!forCountryId.HasValue); }); bool flag4 = !nums.Any <long>(); IEnumerable <ProductSpecificPrice> productSpecificPrices2 = productSpecificPrices1.WhereIf <ProductSpecificPrice>(flag4, (ProductSpecificPrice p) => !p.ForOrganizationalUnitId.HasValue); flag = (!nums.Any <long>() ? false : nums.Count == 1); IEnumerable <ProductSpecificPrice> productSpecificPrices3 = productSpecificPrices2.WhereIf <ProductSpecificPrice>(flag, (ProductSpecificPrice p) => { if (p.ForOrganizationalUnitId.HasValue && p.ForOrganizationalUnitId.Value == nums[0]) { return(true); } return(!p.ForOrganizationalUnitId.HasValue); }); flag1 = (!nums.Any <long>() ? false : nums.Count > 1); List <ProductSpecificPrice> list = productSpecificPrices3.WhereIf <ProductSpecificPrice>(flag1, (ProductSpecificPrice p) => { if (p.ForOrganizationalUnitId.HasValue && nums.Contains(p.ForOrganizationalUnitId.Value)) { return(true); } return(!p.ForOrganizationalUnitId.HasValue); }).ToList <ProductSpecificPrice>(); if (!list.Any <ProductSpecificPrice>()) { str = ""; } else { if (list.Count > 1 & flag3 && nums.Any <long>() && nums.Count == 1) { List <ProductSpecificPrice> productSpecificPrices4 = list; list = list.Where <ProductSpecificPrice>((ProductSpecificPrice x) => { long?forOrganizationalUnitId = x.ForOrganizationalUnitId; long item = nums[0]; if (forOrganizationalUnitId.GetValueOrDefault() != item) { return(false); } return(forOrganizationalUnitId.HasValue); }).ToList <ProductSpecificPrice>(); if (!list.Any <ProductSpecificPrice>() && input.ForCustomerId > 0) { list = productSpecificPrices4.Where <ProductSpecificPrice>((ProductSpecificPrice x) => { long?forCustomerId = x.ForCustomerId; long num = (long)input.ForCustomerId; if (forCustomerId.GetValueOrDefault() != num) { return(false); } return(forCustomerId.HasValue); }).ToList <ProductSpecificPrice>(); } } if (!list.Any <ProductSpecificPrice>()) { str = ""; } else { DateTime?availableFrom = list.First <ProductSpecificPrice>().AvailableFrom; DateTime?availableTo = list.First <ProductSpecificPrice>().AvailableTo; bool flag5 = false; if (!availableFrom.HasValue && !availableTo.HasValue) { flag5 = true; } else if (availableFrom.HasValue && availableTo.HasValue && availableFrom.Value <= DateTime.Now && availableTo.Value >= DateTime.Now) { flag5 = true; } if (!flag5) { str = ""; } else { decimal cost = list.First <ProductSpecificPrice>().Cost; if (empty.Length > 0) { if (empty.Contains("$")) { num1 = decimal.Parse(cost.ToString()) - decimal.Parse(empty.Replace("$", "")); cost = decimal.Parse(num1.ToString()); } else if (empty.Contains("%")) { num1 = decimal.Parse(cost.ToString()) - (decimal.Parse(cost.ToString()) * decimal.Parse(empty.Replace("%", "").ToString())); cost = decimal.Parse(num1.ToString("#.##")); } } if (empty1.Length > 0) { if (empty1.Contains("$")) { num1 = decimal.Parse(cost.ToString()) + decimal.Parse(empty1.Replace("$", "")); cost = decimal.Parse(num1.ToString()); } else if (empty1.Contains("%")) { num1 = decimal.Parse(cost.ToString()) + (decimal.Parse(cost.ToString()) * decimal.Parse(empty1.Replace("%", "").ToString())); cost = decimal.Parse(num1.ToString("#.##")); } } decimal?discount = list.First <ProductSpecificPrice>().Discount; if (discount.HasValue) { decimal?nullable = discount; num1 = new decimal(); flag2 = (nullable.GetValueOrDefault() > num1 ? nullable.HasValue : false); if (flag2) { if (decimal.Parse(discount.ToString()) >= new decimal(0.999)) { cost = decimal.Parse(cost.ToString()) - decimal.Parse(discount.ToString()); } else { num1 = decimal.Parse(cost.ToString()) - (decimal.Parse(cost.ToString()) * decimal.Parse(discount.ToString())); cost = decimal.Parse(num1.ToString("#.##")); } } } str = cost.ToString(); } } } } else { str = ""; } } return(str); }
public static void Main(string[] args) { Console.WriteLine("StringExtensions----"); Console.WriteLine($"String is truncate if longer than 6 char > {"Lorem Ipsum is simply dummy text of the printing and".Truncate(10)}"); Console.WriteLine($"EqualsWithIgnoreCase sample = SAMPLE > {"sample".EqualsWithIgnoreCase("SAMPLE")}"); Console.WriteLine($"IsValidUrl (https://www.github.com) > {"https://www.github.com".IsValidUrl()}"); var sampleJson = "{\"name\":\"turhany\"}"; Console.WriteLine($"IsValidJson ({sampleJson}) > {sampleJson.IsValidJson()}"); Console.WriteLine($"IsValidEmail ([email protected]) > {"*****@*****.**".IsValidEmail()}"); Console.WriteLine($"ComputeHashSha(Key: test) (turhany) > {"turhany".ComputeHashSha("test")}"); Console.WriteLine($"SanitizeHtml(<img src='src' onerror=alert(document.cookie)>deneme) > {"<img src='src' onerror=alert(document.cookie)>deneme".SanitizeHtml()}"); Console.WriteLine($"Slugify (Türhan Yıldırım) > {"Türhan Yıldırım".Slugify()}"); Console.WriteLine($"FromJson ({sampleJson}) > Person.Name = {sampleJson.FromJson<Person>().Name}"); Console.WriteLine($"HashPassword (turhany) > {"turhany".HashPassword()}"); Console.WriteLine($"VerifyPassword (turhany) > {"turhany".VerifyPassword("turhany".HashPassword())}"); var sampleFilePath = Path.Combine(Environment.CurrentDirectory, "logo.png"); Console.WriteLine($"GetFileEncodingByFilePath ({sampleFilePath}) > {sampleFilePath.GetFileEncodingByFilePath()}"); var minifyHtmlResult = "<img src='src' onerror=alert(document.cookie)>deneme".MinifyHtml(true); Console.WriteLine($"MinifyHtml(<img src='src' onerror=alert(document.cookie)>deneme) > SavedInPercent: {minifyHtmlResult.Statistics.SavedInPercent}"); Console.WriteLine($"MinifyHtml(<img src='src' onerror=alert(document.cookie)>deneme) > MinifiedContent: {minifyHtmlResult.MinifiedContent}"); Console.WriteLine(); Console.WriteLine("EnumExtensions----"); Console.WriteLine($"{nameof(Colors.Red)} enum description > {Colors.Red.GetDescription()}"); Console.WriteLine($"{nameof(Colors)} get all enum list - EnumToList > Keys = {string.Join(";",EnumExtensions.EnumToList<Colors>().Select(p => p.Key))}"); Console.WriteLine($"{nameof(Colors)} get all enum list - EnumToList > Values = {string.Join(";",EnumExtensions.EnumToList<Colors>().Select(p => p.Value))}"); List <string> cities = new List <string> { "İstanbul", "Ankara", "İzmir" }; Console.WriteLine(); Console.WriteLine("ListExtensions----"); Console.WriteLine($"RemoveWere (Delete those starting with a) > {string.Join(',', cities.RemoveWhere(p => p.StartsWith("A")))}"); var startsWithI = true; var filteredList = cities.WhereIf(p => p.StartsWith("İ"), startsWithI); Console.WriteLine($"WhereIf (add expression if condition is true) > {string.Join(',', filteredList)}"); Console.WriteLine($"GetPage (pageNumber=1, pageSize=1) > {string.Join(',', cities.GetPage(1, 1))}"); Console.WriteLine($"GetPage (pageNumber=1, pageSize=2) > {string.Join(',', cities.GetPage(1, 2))}"); Console.WriteLine($"SelectRandomFromList > {string.Join(',', cities.SelectRandomFromList(1))}"); Console.WriteLine($"SelectRandomFromList > {string.Join(',', cities.SelectRandomFromList(1))}"); Console.WriteLine(); Console.WriteLine("QueryableExtensions----"); var startsWithIs = true; var filteredQueryableList = cities.AsQueryable().WhereIf(p => p.StartsWith("İs"), startsWithIs); Console.WriteLine($"WhereIf (add expression if condition is true) > {string.Join(',', filteredQueryableList)}"); Console.WriteLine($"AddPaging (pageNumber=1, pageSize=1) > {string.Join(',', cities.AsQueryable().AddPaging(1, 1))}"); Console.WriteLine($"AddPaging (pageNumber=1, pageSize=2) > {string.Join(',', cities.AsQueryable().AddPaging(1, 2))}"); Console.WriteLine(); Console.WriteLine("ObjectExtensions----"); var person = new Person { Name = "Türhan" }; Console.WriteLine($"GetPropertyValue (Name) > {person.GetPropertyValue<string>(nameof(Person.Name))}"); person.SetPropertyValue(nameof(Person.Name), "Türhan Yıldırım"); Console.WriteLine($"GetPropertyValue (Name) > {person.GetPropertyValue<string>(nameof(Person.Name))}"); Console.WriteLine($"GetPropertyInfo (Name) > {person.GetPropertyInfo(nameof(Person.Name))}"); Console.WriteLine($"HasProperty (Name) > {person.HasProperty(nameof(Person.Name))}"); Console.WriteLine($"GetFieldValue (TestField) > {person.GetFieldValue<string>(nameof(Person.TestField))}"); Console.WriteLine($"GetFieldInfo (TestField) > {person.GetFieldInfo(nameof(Person.TestField))}"); Console.WriteLine($"HasField (TestField) > {person.HasField(nameof(Person.TestField))}"); Console.WriteLine($"ToJson > {person.ToJson()}"); Console.WriteLine($"{nameof(Colors.Blue)} enum display name > {Colors.Blue.GetDisplayName()}"); var clonedItem = person.DeepClone(); Console.WriteLine($"DeepClone - Original Object hashCode > {person.GetHashCode()}"); Console.WriteLine($"DeepClone - Original Object hashCode > {clonedItem.GetHashCode()}"); Console.WriteLine($"DeepClone (Name) > {clonedItem.Name}"); Console.WriteLine(); Console.WriteLine("ReflectionExtensions----"); var info = Colors.Red.GetType().GetField(nameof(Colors.Red)); Console.WriteLine($"GetAttribute (Description) > {info.GetAttribute<DescriptionAttribute>().Description}"); Console.WriteLine($"HasAttribute (Description) > {info.HasAttribute<DescriptionAttribute>()}"); cities = new List <string> { "İstanbul", "Ankara", "İzmir", "Adana", "Edirne" }; var batchedList = cities.Batch(2); Console.WriteLine(); Console.WriteLine("EnumerableExtensions----"); Console.WriteLine($"Batch (every batch has 2 element) > 5 item divided 2 item batch"); var batchIndex = 1; foreach (var batch in batchedList) { Console.WriteLine($"{batchIndex}. batch > items -> {string.Join(',', batch.ToList())}"); batchIndex++; } var citiesDictionary1 = new Dictionary <string, string> { { "istanbul", "istanbul" } }; var citiesDictionary2 = new Dictionary <string, string> { { "izmir", "izmir" } }; Console.WriteLine(); Console.WriteLine("DictionaryExtensionMethods----"); citiesDictionary1.Merge(citiesDictionary2); Console.WriteLine($"Merge (Dict1 = istanbul, Dict2 = izmir ) > {string.Join(',',citiesDictionary1.Select(p => p.Key).ToList())}"); Console.WriteLine(); Console.WriteLine("ByteExtensions----"); byte byteEnum = 1; Console.WriteLine($"Byte: {byteEnum} ToEnum cast (Color.Blue = 1) > {byteEnum.ToEnum<Colors>()}"); Console.WriteLine($"Byte: {byteEnum} IsEnumValueValid cast (Color.Blue = 1) > {byteEnum.IsEnumValueValid<Colors>()}"); Console.WriteLine(); Console.WriteLine("IntExtensions----"); int intEnum = 1; Console.WriteLine($"int: {intEnum} ToEnum cast (Color.Blue = 1) > {intEnum.ToEnum<Colors>()}"); Console.WriteLine($"Byte: {intEnum} IsEnumValueValid cast (Color.Blue = 1) > {intEnum.IsEnumValueValid<Colors>()}"); Int64 int64Enum = 1; Console.WriteLine($"int64: {int64Enum} ToEnum cast (Color.Blue = 1) > {int64Enum.ToEnum<Colors>()}"); Console.WriteLine($"Byte: {int64Enum} IsEnumValueValid cast (Color.Blue = 1) > {int64Enum.IsEnumValueValid<Colors>()}"); Console.WriteLine(); Console.WriteLine("BoolExtensions----"); Console.WriteLine($"True bool to AsYesNo > {true.AsYesNo()}"); Console.WriteLine($"False bool to AsYesNo > {false.AsYesNo()}"); bool?testBool = null; Console.WriteLine($"Null (nullable)bool to AsYesNo > {testBool.AsYesNo()}"); testBool = true; Console.WriteLine($"True (nullable)bool to AsYesNo > {testBool.AsYesNo()}"); testBool = false; Console.WriteLine($"False (nullable)bool to AsYesNo > {testBool.AsYesNo()}"); Console.WriteLine(); Console.WriteLine("MessagePackExtensions----"); var serializedPerson = MessagePackExtensions.Serialize(person); var deserializedPerson = MessagePackExtensions.Deserialize <Person>(serializedPerson); Console.WriteLine($"Serialize Person as byte array> {Encoding.UTF8.GetString(serializedPerson, 0, serializedPerson.Length)}"); Console.WriteLine($"Deserialize Person.Name> {deserializedPerson.Name}"); Console.ReadLine(); }