Giter VIP home page Giter VIP logo

hepsi.extensions's Introduction

Hepsi.Extensions v0.1

We have started to share our commonly used extensions for C#. For now, dynamic filtering and ordering is available.

Build status

Installation

Nuget link: https://www.nuget.org/packages/Hepsiburada.Extensions/

PM> Install-Package Hepsiburada.Extensions

Usages

Sorting and filtering by property name was a shameful process if the property is ambiguous at runtime.

DynamicOrderBy

  • IQueryable DynamicOrderBy(this IQueryable source, string propertyName, string direction)
  • IQueryable DynamicOrderBy(this IQueryable source, OrderByRequest orderByRequest)

:(

        public IQueryable<DummyDocument> SortDocuments(IQueryable<DummyDocument> documents, string propertyName)
        {
            switch (propertyName.ToLower())
            {
                case "createdat":
                    return documents.OrderBy(d => d.CreatedAt);
                case "count":
                    return documents.OrderBy(d => d.Count);
                case "id":
                    return documents.OrderBy(d => d.Id);
                case "name":
                    return documents.OrderBy(d => d.Name);
                case "complexype.dummyinteger":
                    return documents.OrderBy(d => d.ComplexType.DummyInteger);
                case "complexype.innercomplextype.dummyinteger":
                    return documents.OrderBy(d => d.ComplexType.InnerComplexType.DummyInnerInteger);

                //Can be hundred cases?... :(

                default:
                    //Can't find the property
                    return documents;
            }
        }

Cool Way

        public IQueryable<DummyDocument> SortDocuments(IQueryable<DummyDocument> documents, string propertyName)
        {
            return documents.DynamicOrderBy(propertyName, "ascending");
        }
        
        //Or you can use our OrderByRequest type as an alternative:
        
        public IQueryable<DummyDocument> SortDocuments(IQueryable<DummyDocument> documents, string propertyName)
        {        
            return documents.DynamicOrderBy(new OrderByRequest(propertyName, OrderByDirection.Ascending));
        }

DynamicFilterBy

  • IQueryable DynamicFiltering(this IQueryable source, string propertyName, string value)

:(

        public IQueryable<DummyDocument> FilterDocuments(IQueryable<DummyDocument> documents, string propertyName, string value)
        {
            switch (propertyName.ToLower())
            {
                case "count":
                    return documents.Where(d => d.Count == Int32.Parse(value));
                case "id":
                    return documents.Where(d => d.Id == Int32.Parse(value));
                case "name":
                    return documents.Where(d => d.Name == value);

                //Can be hundred cases?... :(

                default:
                    //Can't find the property
                    return documents;
            }
        }

Cool Way

        public IQueryable<DummyDocument> FilterDocuments(IQueryable<DummyDocument> documents, string propertyName, string value)
        {
            return documents.DynamicFiltering(propertyName, value);
        }

Note: Dynamic Filtering does not support complex types for now.

Thanks. Hepsiburada Software Development Team

hepsi.extensions's People

Contributors

onatm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

skynyrd

hepsi.extensions's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.