Giter Club home page Giter Club logo

coles's Introduction

COLES

Class Objects Logic Equations and Serializer (COLES) allows you to create "and, or" expression equations using custom class objects and then serialize them to a string representation

alt text

How to use

Inherit the classes you want to objectify and serialize from the GenericCriteria class (feel free to rename the classes) and override the ToString() method as per your serialization requirements

// Name class containing FirstName and LastName properties
public class Name : GenericCriteria
{
  public string FirstName { get; set; }
  public string LastName { get; set; }

  public Name(string firstName, string lastName)
  {
      CriteriaType = "NAME";
      FirstName = firstName;
      LastName = lastName;
  }

  #region Interface Methods

  public override string ToString()
  {
      return CriteriaType + ":" + LastName + "," + FirstName;
  }

  #endregion
}

// Gender class containing GenderType property
public class Gender : GenericCriteria
{
  public enum GenderType
  {
      Unspecified,
      Male,
      Female
  }

  public GenderType PersonGender { get; set; }
  public Gender(GenderType personGender)
  {
      CriteriaType = "GENDER";
      PersonGender = personGender;
  }

  #region Interface Methods

  public override string ToString()
  {
      return CriteriaType + ":" + PersonGender.GetDescription();
  }

  #endregion
}

Now you can include these classes in an equation as below

// John Doe who is a Male and lives in Zip 94587 or 94338
var search1 = new Name("John", "Doe") & new Gender(Gender.GenderType.Male) & (new ZipCode("94587") | new ZipCode("94338"));
Console.WriteLine(search1.ToString());
//OUTPUT: ((NAME:Doe,John && GENDER:Male) && (ZIPCODE:94587 || ZIPCODE:94338))

// John Doe who is a Male or Unknown Gender and lives in Zip 94587 or 94338
var search2 = new Name("John", "Doe") & (new Gender(Gender.GenderType.Male) | new Gender(Gender.GenderType.Unspecified)) & (new ZipCode("94587") | new ZipCode("94338"));
Console.WriteLine(search2.ToString());
//OUTPUT: ((NAME:Doe,John && (GENDER:Male || GENDER:Unspecified)) && (ZIPCODE:94587 || ZIPCODE:94338))

// John Doe who is a Male and lives in Zip 94587 and his Age is 35, 40 or 45
var search3 = new Name("John", "Doe") & (new Gender(Gender.GenderType.Male) & (new ZipCode("94587") & (new Age(35) | new Age(40) | new Age(45) )));
Console.WriteLine(search3.ToString());
//OUTPUT: (NAME:Doe,John && GENDER:Male && ZIPCODE:94587 && (AGE:35 || AGE:40 || AGE:45))

coles's People

Contributors

ubhits avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.