All Projects → kkalinowski → lib12

kkalinowski / lib12

Licence: MIT License
lib12 is a library of universal helpers and extensions useful in any .NET project

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to lib12

XPath2.Net
Lightweight XPath2 for .NET
Stars: ✭ 26 (-13.33%)
Mutual labels:  linq, xml
Stream Parser
⚡ PHP7 / Laravel Multi-format Streaming Parser
Stars: ✭ 391 (+1203.33%)
Mutual labels:  xml, collections
go-streams
Stream Collections for Go. Inspired in Java 8 Streams and .NET Linq
Stars: ✭ 127 (+323.33%)
Mutual labels:  linq, collections
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (+623.33%)
Mutual labels:  xml, collections
linq-collections
Strongly typed Linq and Collections implementation for Javascript and TypeScript (ECMAScript 5)
Stars: ✭ 112 (+273.33%)
Mutual labels:  linq, collections
odin
Data-structure definition/validation/traversal, mapping and serialisation toolkit for Python
Stars: ✭ 24 (-20%)
Mutual labels:  xml
xrechnung-visualization
XSL transformators for web and pdf rendering of German CIUS XRechnung or EN16931-1:2017 [MIRROR OF GitLab]
Stars: ✭ 26 (-13.33%)
Mutual labels:  xml
thinkorm
A flexible, lightweight and powerful Object-Relational Mapper for Node.js. Support TypeScript!!
Stars: ✭ 33 (+10%)
Mutual labels:  sql-query
VectorDrawable2Svg
Converts Android VectorDrawable .xml files to .svg files
Stars: ✭ 50 (+66.67%)
Mutual labels:  xml
dreamland world
DreamLand MUD: all configuration files, and some areas for local dev
Stars: ✭ 16 (-46.67%)
Mutual labels:  xml
try.elinq
Language Integrated Query (LINQ) technology for relational databases and EF Core
Stars: ✭ 21 (-30%)
Mutual labels:  linq
Swift-MathEagle
A general math framework to make using math easy. Currently supports function solving and optimisation, matrix and vector algebra, complex numbers, big int, big frac, big rational, graphs and general handy extensions and functions.
Stars: ✭ 41 (+36.67%)
Mutual labels:  mathematics
blogspot-themes
Blogspot (Blogger) Themes Library
Stars: ✭ 32 (+6.67%)
Mutual labels:  xml
algo-ds-101
Curated list of data structures and algorithms in 10+ programming languages.
Stars: ✭ 154 (+413.33%)
Mutual labels:  collections
discourse-data-explorer
SQL Queries for admins in Discourse
Stars: ✭ 70 (+133.33%)
Mutual labels:  sql-query
utils.js
👷 🔧 zero dependencies vanilla JavaScript utils.
Stars: ✭ 14 (-53.33%)
Mutual labels:  xml
Linear Feedback Shift Register
Linear Feedback Shift Register
Stars: ✭ 34 (+13.33%)
Mutual labels:  random-generation
Program-Matematika
Program Matematika adalah sebuah repository GitHub yang berisi program yang dapat memudahkan para pelajar atau guru dalam menyelesaikan masalah Matematika dengan Terminal
Stars: ✭ 15 (-50%)
Mutual labels:  mathematics
xgen
XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
Stars: ✭ 153 (+410%)
Mutual labels:  xml
Config
PHP library for simple configuration management
Stars: ✭ 39 (+30%)
Mutual labels:  xml

alt tag

Build Status NuGet Version

The purpose of lib12 is to replace common code present in any .NET project with one NuGet. This is done by extending the standard API in three ways:

  • with extensions methods to standard types like string.IsNotNullAndNotEmpty, string.RemoveDiacritics, IEnumerable.LeftJoin or DateTime.GetWeek
  • by giving developer new constructs like CollectionFactory or Execution classes
  • by adding not standard utilities that could be very useful in specific circumstances like fluent SQL builder or reverse polish notation formula parser All of these functionalities are created with a wide array of possible use cases in mind and covered with unit tests

Current version available on nuget - https://www.nuget.org/packages/lib12

My blog describing how I work on library and its content - https://kkalinowski.net/2018/10/07/lib12-my-helper-library/

Table of Contents

  1. Data
    1. Fluent SQL query builder
    2. Dummy and random data
    3. Geopolitical data
    4. XML extensions
  2. Mathematical functions
  3. Collections
  4. Reflection
    1. Extensions
    2. Creation by enum
  5. Extensions methods
  6. Utilities
  7. Checking utilities

Fluent SQL query builder

Namespace - lib12.Data.QueryBuilding

In spite of overwhelming popularity of various ORMs you still have to write some SQL query from time to time. Maintaining and storing those queries can be tricky. To help with that I created fluent SQL query builder. It supports most important SQL keywords for select, insert, update and delete. Using it is quite simple:

var select = SqlBuilder.Select.Fields(fields).From("products", "p")
	.Join("groups", "g", "p.group_id", "g.id")
	.Join("stores", "s", "g.id", "s.group_id", JoinType.Left)
	.OpenBracket()
	.Where("price", Compare.GreaterThan, 100).And.Where("price", Compare.LessOrEquals, 1000)
	.CloseBracket()
	.Or.Where("code", Compare.Like, "a%")
	.GroupBy("product_group").Having("avg(price)>100")
	.OrderByDesc("price").Build();
	
var insert = SqlBuilder.Insert.Into("product").Columns("type", "price", "name").Values(4, 5, "test").Build();

var batchInsertQuery = SqlBuilder.Insert.Into("product").Columns("Prop1", "Prop2").Batch(
    new[]{
		new Values{Prop1 = "test", Prop2 = 21},
		new Values{Prop1 = "test2", Prop2 = 8}
    }).Build();
    
var insertIntoSelect = SqlBuilder.Insert.Into("product").Columns("name","price")
	.Select(SqlBuilder.Select.AllFields.From("product_test").Build())
    .Build();

var update = SqlBuilder.Update.Table("product").Set("price", 5).Set("name", "test").OpenBracket()
	.Where("price", Compare.Equals, 1).And.Where("type", Compare.Equals, 3).CloseBracket()
	.Or.Where("type", Compare.NotEquals, 3)
	.Build();
	
var delete = SqlBuilder.Delete.From("product").OpenBracket()
	.Where("price", Compare.Equals, 1).And.Where("type", Compare.Equals, 3).CloseBracket()
	.Or.Where("type", Compare.NotEquals, 3)
	.Build()

Dummy and random data

Namespace - lib12.Data.Random

Sometimes when you start developing new project you don't have data to test your solution. lib12 contains classes that will help you to quickly solve this problem. Rand contains methods to quickly generate collection of random data:

public class ClassToGenerate
{
    public enum EnumToGenerate
    {
        First,
        Second,
        Third
    }

    public class Nested
    {
        public string NestedText { get; set; }
    }

    public string Text { get; set; }
    public EnumToGenerate Enum { get; set; }
    public bool Bool { get; set; }
    public int Int { get; set; }
    public double Double { get; set; }
    public int NumberThatShouldntBeSet { get; } = 12;
    public int NumberImpossibleToSet { get { return 12; } }
    public Nested NestedClass { get; set; }
}

var generated = Rand.NextArrayOf<ClassToGenerate>(CollectionSize);

lib12.Data.Random contains also methods from System.Random class and additional methods for generating bool, char, string, enums and DateTime in one easy to use static Rand class. Also FakeData class contains preprogramed set of names, companies, geodata to quickly generate useful data for your application tests.

Geopolitical data

lib12.Data.Geopolitical.CountryRepository contains list of countries (AllCountries property) and also easily accessible objects (SingleCountries property). Apart from name you can also get information about languages, capital, currencies and more.

XML extensions

Contains extensions methods for Xml classes to create xmls in fluent way.

Mathematical functions

Namespace - lib12.Mathematics

Formula class use Reverse Polish Notation to parse and compute mathematical expressions:

var formula = new Formula("-12*3 + (5-3)*6 + 9/(4-1)");
var result = formula.Evaluate();

This class understands variables, so you can compile it once and use for many computations:

var formula = new Formula("a*(5-b)");
formula.Evaluate(new { a = 10, b = 3 });

Mathematics namespace contains also Math2 class which contains many helper functions like Next, Prev, IsEven or IsOdd.

Collections

Namespace - lib12.Collections

  • IEnumerableExtension contains methods that easier working with standard collections like Foreach, IsNullOrEmpty, Recover (which acts as null pattern object simplifying null checking), ToDelimitedString, IntersectBy, MaxBy, LeftJoin, etc.
  • lib12.Collections.ICollectionExtension - AddRange, RemoveRange, RemoveBy
  • lib12.Collections.IDictionaryExtension - GetValueOrDefault, Recover, Concat and ToReadOnlyDictionary
  • lib12.Collections.ArrayExtension - methods to Flatten multi dimensional arrays
  • lib12.Collections.CollectionFactory - creates collections in functional way
  • lib12.Collections.Empty - creates empty collections using fluent syntax
  • lib12.Collections.Packing - contains class Pack to quickly pack set of loose objects into collection and extension methods for single object to do that
  • lib12.Collections.Paging - contains extension methods GetPage, GetNumberOfPages and GetPageItems to simplify working with paging

Reflection

Extensions

Namespace - lib12.Reflection

Reflection namespace contains a lot of useful extension methods that make working with .NET reflection mechanism easier and more straightforward:

  • easier work with attributes - all reflection entities like Type, FieldInfo, PropertyInfo, etc. and also enum fields contains method GetAttribute<> for retrieving decorating attribute and also IsMarkedWithAttribute<> to check if entity is decorated with given attribute
  • checking properties of constructs - with methods like IsStatic, IsNullable, IsNumber, IsImplementingInterface and more you can quickly check more advance properties of types, fields and properties
  • accessing object data through reflection - with methods like GetConstants, GetPropertyValueByName or GetFieldValueValueByName
  • manipulating objects - creating objects with CreateInstance<>, calling methods with CallMethodByName or setting object state with SetPropertyValueByName

Creation by enum

Namespace - lib12.Reflection.CreationByEnum

This unique mechanism allows you to create whole objects based on current data state. It could be useful to i.e. create strategies to handle data based on single value:

public enum OrderState
{
    [CreateType(typeof(SendNotificationStrategy))]
    Created,
    [CreateType(typeof(CreatePaymentStrategy))]
    Ordered,
    [CreateType(typeof(AlterInventoryStrategy))]
    Payed,
    [CreateType(typeof(AddToReportStrategy))]
    Archived,
}

public class Order
{
    //...
    public OrderStatus Status { get; set; }
    //...
}

//...

var strategy = order.Status.CreateType<IStrategy>();
strategy.Execute();

Extensions methods

Namespace - lib12.Extensions

  • String - methods like EqualsCaseInsensitive, Truncate, ContainsCaseInsensitive, RemoveDiacritics or GetNumberOfOccurrences
  • DateTime - allows to manipulate weeks and quarter, get start and end of week and month, get persons age or check date (IsWorkday, IsWeekend, IsInPast, IsInFuture)
  • Nullable bool - quick checks remove redundant code like IsTrue or IsNullOrFalse
  • Exception - GetInnerExceptions and GetMostInnerException
  • Func - method to convert function to non generic version

Utilities

  • lib12.Utlity.Comparing - contains generic PropertyOrderComparer and PropertyEqualityComparer that implements IComparer and IEqualityComparer respectively so for simple one property checks you don't have to implement whole Comparer class
  • lib12.Utility.Execution - utilities to work with function calls - Repeat, Benchmark, Retry and Memoize
  • lib12.Utility.Range - generic class for dealing with ranges
  • lib12.Utility.IoHelper - additional methods for IO
  • lib12.Utility.Logger - simple logger, that doesn't need additional configuration
  • lib12.Utility.UnknownEnumException - exception to better interpret missing case for enum

Checking utilities

Namespace - lib12.Checking

Contains Check class to quickly simplify null checking on set objects like Check.AllAreNull or Check.AnyIsNull. This namespace also contains extensions for equality check against set of objects like object.IsAnyOf(object1, object2, object3)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].