{"id":15002901,"url":"https://github.com/vaseug/powerlib","last_synced_at":"2026-02-02T00:35:42.321Z","repository":{"id":137906657,"uuid":"87435672","full_name":"vaseug/PowerLib","owner":"vaseug","description":"PowerLib contains classes and extension methods for working with data structures and MSSQL server data.","archived":false,"fork":false,"pushed_at":"2018-02-18T23:08:58.000Z","size":1365,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T04:20:24.142Z","etag":null,"topics":["arrays","collections","data-structures","database","deployment","entityframework","helpers","linq","linq2sql","mssqlserver","sqlclr","sqlserver"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vaseug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-06T14:00:45.000Z","updated_at":"2023-03-10T10:47:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"4865528a-0b9a-4cf7-b659-f1b326774e27","html_url":"https://github.com/vaseug/PowerLib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vaseug/PowerLib","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaseug%2FPowerLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaseug%2FPowerLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaseug%2FPowerLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaseug%2FPowerLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vaseug","download_url":"https://codeload.github.com/vaseug/PowerLib/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vaseug%2FPowerLib/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261238895,"owners_count":23128879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","collections","data-structures","database","deployment","entityframework","helpers","linq","linq2sql","mssqlserver","sqlclr","sqlserver"],"created_at":"2024-09-24T18:53:56.792Z","updated_at":"2026-02-02T00:35:42.281Z","avatar_url":"https://github.com/vaseug.png","language":"C#","readme":"# **PowerLib**\n\nThis solution contains the following projects:\n\n* **[PowerLib.System](#PowerLib.System.Data)**\n* **[PowerLib.System.Data](#PowerLib.System.Data)**\n* **[PowerLib.System.Data.Linq](#PowerLib.System.Data.Linq)**\n* **[PowerLib.EntityFramework](#PowerLib.EntityFramework)**\n* **[PowerLib.System.Data.SqlTypes](#PowerLib.System.Data.SqlTypes)**\n* **[PowerLib.SqlServer](#PowerLib.SqlServer)**\n* **[PowerLib.SqlServer.Web](#PowerLib.SqlServer.Web)**\n* **[PowerLib.SqlClr.Deploy](#PowerLib.SqlClr.Deploy)**\n* **[PowerLib.SqlClr.Deploy.Utility](#PowerLib.SqlClr.Deploy.Utility)**\n\nAfter successfully building the solution, a folder with the configuration name will be located at its root. It will contains the following folders:\n* **PWRLIB** - PowerLib general assemblies,\n* **PWRSQL** - SQLCLR assemblies for deploying on MSSQL Server,\n* **SQLCLRDU** - utility for deploying any SQLCLR assemblies on MSSQL Server.\n\n---\n## PowerLib.System\n\nContains many classes, structures, interfaces and extension methods that expedite and optimize the development process.\n\n### Arrays\n\nFor working with arrays jagged and regular (one-dimensional, multidimensional), there are many classes and extension methods. For example, the following are the extension methods for working with regular arrays.\n```csharp\n// Creates regular array with specified lengths and lowerBounds.\npublic static Array CreateAsRegular\u003cT\u003e(int[] lengths, int[] lowerBounds = null);\n\n// Enumerates regular array elements.\npublic static IEnumerable\u003cT\u003e EnumerateAsRegular\u003cT\u003e(this Array array, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Creates a shallow copy of the regular array.\npublic static Array CloneAsRegular(this Array array);\n\n// Returns a regular array from its string representation.\npublic static Array ParseAsRegular\u003cT\u003e(string s, Func\u003cstring, int, int[], T\u003e itemParser, string itemPattern, char[] delimitChars, char[] spaceChars, char[] escapeChars, char[] openingChars, char[] closingChars);\n\n// Converts a regular array to its string representation.\npublic static string FormatAsRegular\u003cT\u003e(this Array array, Func\u003cT, int, int[], string\u003e itemFormatter, Func\u003cint, string\u003e itemDelimiter, Func\u003cint, string\u003e openBracket, Func\u003cint, string\u003e closeBracket, int[] indices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Enumerates a regular array elements and projects each element of the array into a new form.\npublic static IEnumerable\u003cTResult\u003e SelectAsRegular\u003cTSource, TResult\u003e(this Array array, Func\u003cTSource, int, int[], TResult\u003e selector, int[] indices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Enumerates a regular array elements and filters elements based on a predicate.\npublic static IEnumerable\u003cT\u003e WhereAsRegular\u003cT\u003e(this Array array, Func\u003cT, int, int[], bool\u003e predicate, int[] indices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Apply action to elements of a regular array.\npublic static void ApplyAsRegular\u003cT\u003e(this Array array, Action\u003cT, int, int[]\u003e action, int[] indices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Initialize elements of a regular array.\npublic static void FillAsRegular\u003cT\u003e(this Array array, Func\u003cint, int[], T\u003e valuator, int[] indices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// Converts one regular array to another with the possibility of applying transposition and the conversion of the values of the elements.\npublic static Array ConvertAsRegular\u003cTSource, TResult\u003e(this Array array, Func\u003cTSource, int, int[], int, int[], TResult\u003e converter, int[] transposition = null, int[] lowerBounds = null, int[] targetIndices = null, int[] sourceIndices = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n\n// \npublic static Array RangeAsRegular(this Array array, int[] transposition = null, int[] lowerBounds = null, bool zeroBased = false, Range? range = null, params Range[] ranges);\n```\nThe following are the extension methods for working with jagged arrays.\n```csharp\n// Creates jagged array with specified structures.\npublic static Array CreateAsJagged\u003cT\u003e(int[] ranks, Func\u003cint, int[], int[][], int[]\u003e lensGetter, int[] bandedIndices = null, int[][] rankedIndices = null);\n\n// Enumerate jagged array elements\npublic static IEnumerable\u003cT\u003e EnumerateAsJagged\u003cT\u003e(this Array array, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Converts a jagged array to its string representation.\npublic static string FormatAsJagged\u003cT\u003e(this Array array, Func\u003cT, int, int[], int[][], string\u003e itemFormatter, Func\u003cint, string\u003e nullFormatter, Func\u003cint, int, int, string\u003e itemDelimiter, Func\u003cint, int, int, string\u003e openBracket, Func\u003cint, int, int, string\u003e closeBracket, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Enumerates a jagged array elements and projects each element of the array into a new form.\npublic static IEnumerable\u003cTResult\u003e SelectAsJagged\u003cTSource, TResult\u003e(this Array array, Func\u003cTSource, int, int[], int[][], TResult\u003e selector, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Enumerates a jagged array elements and filters elements based on a predicate.\npublic static IEnumerable\u003cT\u003e WhereAsJagged\u003cT\u003e(this Array array, Func\u003cT, int, int[], int[][], bool\u003e predicate, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Initialize elements of a jagged array.\npublic static void FillAsJagged\u003cT\u003e(this Array array, Func\u003cint, int[], int[][], T\u003e valuator, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Apply action to elements of a jagged array.\npublic static void ApplyAsJagged\u003cT\u003e(this Array array, Action\u003cT, int, int[], int[][]\u003e action, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n\n// Converts one jagged array to another with conversion of the values of the elements.\npublic static Array ConvertAsJagged\u003cTSource, TResult\u003e(this Array array, Func\u003cTSource, int, int[], int[][], TResult\u003e converter, int[] bandedIndices = null, int[][] rankedIndices = null, bool zeroBased = false, Func\u003cint, int[], int[][], bool, Range[]\u003e ranger = null);\n```\nThe following simple code shows the enumeration of the jagged array elements\n```csharp\n  var ja = new int[][][,]\n  {\n    new[]\n    {\n      new int[,]\n      {\n        { 1, 2 },\n        { 3, 4 },\n        { 5, 6 },\n        { 7, 8 },\n      },\n      new int[,]\n      {\n        { 11, 12, 13, 14 },\n        { 21, 22, 23, 24 },\n        { 31, 32, 33, 34 },\n      }\n    },\n    new[]\n    {\n      new int[,]\n      {\n        { 111, 112, 113, 114, 115 },\n        { 121, 122, 123, 124, 125 },\n        { 131, 132, 133, 134, 135 },\n      }\n    }\n  };\n  \n  Console.WriteLine(string.Join(\",\", ja.EnumerateAsJagged\u003cint\u003e()));\n```\nand produces the following result:\n```\n1,2,3,4,5,6,7,8,11,12,13,14,21,22,23,24,31,32,33,34,111,112,113,114,115,121,122,123,124,125,131,132,133,134,135\n```\n### Collections\n\nThe **ListExtension** class contains a number of extension methods for working with lists.\n\n#### Lists\n\n**PowerLib.System.Collection.PwrList\\\u003cT\u003e** - A list whose operation with an internal buffer is based on the round-robin algorithm. It implements the memory allocation and deallocation management interfaces and contains many methods for working with its elements.\n\n**PowerLib.System.Collection.PwrSortedList\\\u003cT\u003e** - Sorted list based on the comparator of elements represented by the interface *IComparer\\\u003cT\u003e* or the delegate *Comparison\\\u003cT\u003e*. The values of the elements participating in the comparison must be unchanged during the storage in the list. The list can be restricted by storing only unique values. There are also options that control the addition of duplicate values: to the beginning of the chain, to the end, or arbitrarily.\n\n**PowerLib.System.Collection.PwrKeySortedList\\\u003cK, T\u003e** - Sorted list based on the element key comparator represented by the *IComparer\\\u003cK\u003e* interface or the *Comparison\\\u003cK\u003e* delegate. The key extraction is specified by the delegate *Func\\\u003cT, K\u003e*. The key values of the elements participating in the comparison must be unchanged during the storage in the list. The list can be restricted by storing only unique values. There are also options that control the addition of duplicate values: to the beginning of the chain, to the end, or arbitrarily.\n\n#### Stacks\n\n**PowerLib.System.Collection.PwrStack\\\u003cT\u003e** - A general stack with additional range operations.\n**PowerLib.System.Collection.PwrSortedStack\\\u003cT\u003e** - A sorted stack (priority stack).\n**PowerLib.System.Collection.PwrKeySortedStack\\\u003cT\u003e** - A key sorted stack (priority stack).\n\n#### Queues\n\n**PowerLib.System.Collection.PwrQueue\\\u003cT\u003e** - A general queue with additional range operations.\n**PowerLib.System.Collection.PwrSortedQueue\\\u003cT\u003e** - A sorted queue (priority queue).\n**PowerLib.System.Collection.PwrKeySortedQueue\\\u003cT\u003e** - A key sorted queue (priority queue).\n\n#### Deques\n\n**PowerLib.System.Collection.PwrDeque\\\u003cT\u003e** - A general deque with additional range operations.\n**PowerLib.System.Collection.PwrSortedDeque\\\u003cT\u003e** - A sorted deque (priority deque).\n**PowerLib.System.Collection.PwrKeySortedDeque\\\u003cT\u003e** - A key sorted deque (priority deque).\n\n#### Bitwise\n...\n#### Linked list\n...\n#### Trees\n...\n#### Graphs\n...\n#### Matching\nThere are many classes in namespace **PowerLib.System.Collection.Matching** for working with items matching and comparison.\n\n### IO\n#### Streaming\n...\n#### Filesystem\n\nTo work with the file system, the **PowerLib.System.IO.FileSystemInfoExtension** class exists, which allows you to display hierarchical information about the file structure using flexible filtering and sorting capabilities. Also, group operations for deleting and moving (renaming) files by condition are supported. For example, search files with max depth: 2 (0 - unrestricted depth), file extension: \"\\***.csproj**\", directory starts with: \"**PowerLib.**\" and output by directory name *descending order* and file name *ascending order*.\n```csharp\n  foreach (var item in new DirectoryInfo(@\"D:\\Projects\\Github\\PowerLib\\\").EnumerateFiles(\"*\", 2, FileSystemTraversalOptions.ExcludeStart | FileSystemTraversalOptions.ExcludeEmpty, \n    fi =\u003e fi.Extension == \".csproj\", (x, y) =\u003e Comparable.Compare(x.Name, y.Name, false),\n    di =\u003e di.Name.StartsWith(@\"PowerLib.\"), (x, y) =\u003e Comparable.Compare(x.Name, y.Name, false) * -1))\n    Console.WriteLine(\"{0}\", Path.Combine(item.DirectoryName, item.Name));\n```\nConsole output:\n```\nD:\\Projects\\Github\\PowerLib\\PowerLib.System.Data.SqlTypes\\PowerLib.System.Data.SqlTypes.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.System.Data.Linq\\PowerLib.System.Data.Linq.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.System.Data\\PowerLib.System.Data.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.System.ComponentModel.DataAnnotations\\PowerLib.System.ComponentModel.DataAnnotations.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.System\\PowerLib.System.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.SqlServer\\PowerLib.SqlServer.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.SqlClr.Deploy.Utility\\PowerLib.SqlClr.Deploy.Utility.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.SqlClr.Deploy\\PowerLib.SqlClr.Deploy.csproj\nD:\\Projects\\Github\\PowerLib\\PowerLib.EntityFramework\\PowerLib.EntityFramework.csproj\n```\nBelow are the prototypes of functions for working with the elements of the file system with the most complete number of arguments:\n```csharp\n//\tEnumerate abstract filesystem items\npublic static IEnumerable\u003cFileSystemInfo\u003e EnumerateFileSystemInfos\u003cDI\u003e(this DI diParent, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cFileSystemInfo, bool\u003e predicate, Comparison\u003cFileSystemInfo\u003e comparison, Func\u003cDI, IEnumerable\u003cFileSystemInfo\u003e\u003e getChildren, Func\u003cFileSystemInfo, bool\u003e hasChildren)\nwhere DI : FileSystemInfo;\n\n//\tEnumerate filesystem items\npublic static IEnumerable\u003cFileSystemInfo\u003e EnumerateFileSystemInfos(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cFileSystemInfo, bool\u003e predicate, Comparison\u003cFileSystemInfo\u003e comparison);\n\n//\tEnumerate files\npublic static IEnumerable\u003cFileInfo\u003e EnumerateFiles(this DirectoryInfo diStart, string searchPattern, int maxDepth, bool direction, Func\u003cFileInfo, bool\u003e filePredicate, Comparison\u003cFileInfo\u003e fileComparison, Func\u003cDirectoryInfo, bool\u003e dirPredicate, Comparison\u003cDirectoryInfo\u003e dirComparison);\n\n//\tEnumerate directories\npublic static IEnumerable\u003cDirectoryInfo\u003e EnumerateDirectories(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cDirectoryInfo, bool\u003e predicate, Comparison\u003cDirectoryInfo\u003e comparer);\n\n// Move (rename) filesystem items\npublic static int MoveTo(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions,  Func\u003cFileSystemInfo, bool\u003e predicate, Func\u003cFileSystemInfo, string\u003e replacing);\n\n// Delete filesytem items\npublic static int Delete(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cFileSystemInfo, bool\u003e predicate, bool recursive);\n```\nThere are also functions with a predicate, the parameter of which, together with the element, is the context of the hierarchy of type IHierarchicalContext\\\u003cDirectoryInfo\\\u003e containing the list of ancestors:\n```csharp\n//\tEnumerate abstract filesystem items\npublic static IEnumerable\u003cFileSystemInfo\u003e EnumerateFileSystemInfos\u003cDI\u003e(this DI diParent, int maxDepth, FileSystemTraversalOptions traversalOptions, HierarchicalContext\u003cDI\u003e context, Func\u003cElementContext\u003cFileSystemInfo, IHierarchicalContext\u003cDI\u003e\u003e, bool\u003e predicate, Comparison\u003cFileSystemInfo\u003e comparison, Func\u003cDI, IEnumerable\u003cFileSystemInfo\u003e\u003e getChildren, Func\u003cFileSystemInfo, bool\u003e hasChildren) where DI : FileSystemInfo;\n\n//\tEnumerate files\npublic static IEnumerable\u003cFileInfo\u003e EnumerateFiles(this DirectoryInfo diStart, string searchPattern, int maxDepth, bool direction, Func\u003cElementContext\u003cFileInfo, IHierarchicalContext\u003cDirectoryInfo\u003e\u003e, bool\u003e filePredicate, IComparer\u003cFileInfo\u003e fileComparer, Func\u003cElementContext\u003cDirectoryInfo, IHierarchicalContext\u003cDirectoryInfo\u003e\u003e, bool\u003e dirPredicate, Comparison\u003cDirectoryInfo\u003e dirComparison);\n\n//\tEnumerate directories\npublic static IEnumerable\u003cDirectoryInfo\u003e EnumerateDirectories(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cElementContext\u003cDirectoryInfo, IHierarchicalContext\u003cDirectoryInfo\u003e\u003e, bool\u003e predicate, Comparison\u003cDirectoryInfo\u003e comparison);\n\n// Move (rename) filesystem items\npublic static int MoveTo(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cElementContext\u003cFileSystemInfo, IHierarchicalContext\u003cDirectoryInfo\u003e\u003e, bool\u003e predicate, Func\u003cFileSystemInfo, string\u003e replacing);\n            \n// Delete filesytem items\npublic static int Delete(this DirectoryInfo diStart, string searchPattern, int maxDepth, FileSystemTraversalOptions traversalOptions, Func\u003cElementContext\u003cFileSystemInfo, IHierarchicalContext\u003cDirectoryInfo\u003e\u003e, bool\u003e predicate, bool recursive);\n```\n\n### Builders\n\nAlso, in namespace **PowerLib.System.Linq.Builders** there are classes that allow you to build complex predicative expressions, comparison expressions, access (initializetion, copy, call) expressions to fields, properties, and methods. Very useful for compiling predicative Queryable expressions depending on the current runtime filtering conditions. For example, predicate expression with anonymous type:\n```csharp\n  DateTime? birthday = new DateTime(1990, 1, 1);\n  var predicate = PredicateBuilder\n    .Matching(() =\u003e new { id = default(int), name = default(string), birthday = default(DateTime?) })\n    .Match(t =\u003e t.name == \"Mike\");\n  if (birthday.HasValue)\n    predicate = predicate.And(t =\u003e t.birthday.HasValue \u0026\u0026 t.birthday.Value \u003e= birthday.Value);\n  dc.Persons\n    .Select(t =\u003e new { id = t.Id, name = t.Name, birthday = t.Birthday })\n    .Where(predicate.Expression)\n    .ToArray();\n```\nThe following example demonstrates how to create complex comparer using ComparerBuilder class:\n```csharp\n  public class Person\n  {\n    private int id;\n    public string Name { get; set; }\n    public DateTime Birthday { get; set; }\n    public double GetSalary(int year);\n  }\n\n  var comparer = ComparerBuilder.Comparison\u003cPerson\u003e()\n    .Descend(t =\u003e t.Birthday)\n    .Ascend(t =\u003e t.Name)\n    .Descend(ReflectionBuilder.InstancePropertyAccess\u003cPerson, int\u003e(pi =\u003e pi.Name == \"id\"))\n    .Comparer(); //\tresult is IComparer\u003cPerson\u003e type\n\n  int year;\n\n  var comparison = ComparerBuilder.Comparison\u003cPerson\u003e()\n    .Descend(t =\u003e t.GetSalary(year))\n    .Ascend(t =\u003e t.Name)\n    .Comparison(); // Comparison\u003cPerson\u003e with external variable parameter \n```\nThe following example demonstrates how to create an object and call its private method using the Reflection Builder class:\n```csharp\n  public class MyExpr\n  {\n    private int _factor;\n\n    private MyExpr(int factor)\n    {\n      _factor = factor;\n    }\n\n    private string Method(int x, int y)\n    {\n      return ((x + y) * _factor).ToString();\n    }\n  }\n  \n  public string Test()\n  {\n    var arguments = Tuple.Create(7, 8, 3);\n\n    var factory = ReflectionBuilder\n      .Construct\u003cMyExpr\u003e(ci =\u003e ci.GetParameters().Length == 1, c =\u003e c.ByVal(pi =\u003e pi.Position == 0, arguments.Item3))\n      .Compile();\n\n    var action = ReflectionBuilder\n      .InstanceMethodCall(mi =\u003e mi.Name == \"Method\" \u0026\u0026 mi.IsPrivate,\n        Call\u003cMyExpr\u003e.Expression(call =\u003e call.ByVal(pi =\u003e pi.Position == 0, arguments.Item1).ByVal(pi =\u003e pi.Position == 1, arguments.Item2).Return\u003cstring\u003e()))\n        .Compile();\n\n    return action(factory());\n  }\n```\nContinued...\n\n---\n## PowerLib.System.Data\n\nContains code to working with data objects.\nThe DataTypeAdapter class is intended to organize the conversion between the storage type and the representation type of data object. The class is abstract and declares two public properties: StoreValue - for the value on the storage side and ViewValue - for the value on the view side. Conversion between values is carried out on demand. The following classes are derived from the DataTypeAdapter:\n* __BytesBinaryFormatterAdapter__\n* __BytesBinarySerializeAdapter\\\u003cT\\\u003e__\n* __StreamedCollectionAdapter\\\u003cT, V\\\u003e__\n* __StringXmlSerializableAdapter\\\u003cT\\\u003e__\n* __StringXmlSerializerAdapter__\n* __XElementXmlSerializableAdapter\\\u003cT\\\u003e__\n* __XElementXmlSerializerAdapter__\n\nThe PowerLib.SqlServer library provides a functional that allows you to work with regular (one-dimensional or multidimensional) arrays or collections of simple data types stored in a binary data type. On the client side, work with these types of data can be done either by calling the functions of the PowerLib.SqlServer library through EntityFramework or LINQ2SQL, or by converting to the representing type and vice versa. The following example shows the use of the StreamedCollectionAdapter for these purposes.\n```csharp\npublic class SampleEntity\n{\n    private StreamedCollectionAdapter\u003cint?, int[]\u003e _indicesAdapter = new StreamedCollectionAdapter\u003cint?, int[]\u003e(null, null, false,\n      s =\u003e new NulInt32StreamedArray(s, false, false), c =\u003e c.Select(t =\u003e t.Value).ToArray(),\n      (s, c) =\u003e new NulInt32StreamedArray(s, SizeEncoding.B1, true, c.Select(v =\u003e (int?)v).Counted(c.Length), false, false));\n\n    [Column(\"DimIndices\")]\n    public Byte[] RawIndices\n    {\n      get { return _indicesAdapter.StoreValue; }\n      set { _indicesAdapter.StoreValue = value; }\n    }\n\n    [NotMapped]\n    public int[] DimIndices\n    {\n      get { return _indicesAdapter.ViewValue; }\n      set { _indicesAdapter.ViewValue = value; }\n    }\n}\n```\n\n---\n## PowerLib.System.Data.Linq\n\nExtends LINQ to SQL for working with functions from the PowerLib.SqlServer assembly. Simply inherit your DataContext from PowerLib.System.Data.Linq.PwrDataContext.\n\nSamples:\n\n1. Getting an entity person who has a phone number in XML containing three digits `555` before the four end digits. All filtering actions are performed on the SQL server side.\n\n```csharp\n  using (var dc = new MyDataContext())\n  {\n    var ns = @\"def=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo\"\n           + @\";crm=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord\"\n           + @\";act=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes\";\n    var persons = dc.Person\n      .Where(t =\u003e dc.regexIsMatch(dc.xmlEvaluateAsString(t.AdditionalContactInfo, \"/def:AdditionalContactInfo/crm:ContactRecord/act:telephoneNumber/act:number/text()\", ns), @\"555-\\d{4}$\", RegexOptions.None) == true)\n      .ToArray();\n    }\n```\nContinued...\n\n---\n## PowerLib.EntityFramework\n\nExtends EntityFramework for working with MSSQL server functions and stored procedures, and for working with functions from the PowerLib.SqlServer assembly. In CodeFirst inherit your DbContext from PowerLib.System.Data.Entity.PwrDbContext with same name, but in other namespace. In method OnModelCreating call this method base class implementation.\n\nSamples:\n\n1. Getting an entity person who has a phone number in XML containing three digits `555` before the four end digits. All filtering actions are performed on the SQL server side.\n\n```csharp\n  using (var dc = new PwrDbContext())\n  {\n    var ns = @\"def=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactInfo\"\n           + @\";crm=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactRecord\"\n           + @\";act=http://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ContactTypes\";\n    var persons = dc.Person\n      .Where(t =\u003e dc.regexIsMatch(dc.xmlEvaluateAsString(t.AdditionalContactInfo,  \"/def:AdditionalContactInfo/crm:ContactRecord/act:telephoneNumber/act:number/text()\", ns), @\"555-\\d{4}$\", RegexOptions.None) == true)\n      .ToArray();\n  }\n```\n\nContinued...\n\n---\n## PowerLib.System.Data.SqlTypes\n\nContains several dozens of user-defined types (UDTs) and functions:\n\n- __SqlRegex__ - Represents a regular expression (System.Text.RegularExpressions.Regex type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlBigInteger__ - Represents a big integer (System.Numerics.BigInteger type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlComplex__ - Represents a complex number (System.Numerics.Complex type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlGradAngle__ - Represents a grad angle (PowerLib.System.Numerics.GradAngle type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlHourAngle__ - Represents a hour angle (PowerLib.System.Numerics.HourAngle type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlSexagesimalAngle__ - Represents a sexagesimal angle (PowerLib.System.Numerics.SexagesimalAngle type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlZipArchive__ - Represents a zip archive (System.IO.Compression.ZipArchive type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlRange__ - Represents a range - integer index and count (PowerLib.System.Range type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlLongRange__ - Represents a long range - long integer index and count (PowerLib.System.Range type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlUri__ - Represents an uri - Uniform Resource Identifier (URI) value (System.Uri type) to be stored in or retrieved from a database and and having its methods and properties.\n- __SqlFileInfo__ - Represents a file path value to be stored in or retrieved from a database and and having methods and properties to work with file located at path.\n- __SqlDirectoryInfo__ - Represents a directory path value to be stored in or retrieved from a database and and having methods and properties to work with directory located at path.\n- __SqlNameValueCollection__ - Represents collection of associated string keys and string values that can be accessed either with the key or with the index.\n- __Sql__\u003c*ClrType*\u003e__Collection__ - Represents collection items of \u003c*Type*\u003e type to be stored in or retrieved from a database. In SQL server collection names as \u003c*DbType*\u003e__Collection__.\n- __Sql__\u003c*ClrType*\u003e__Array__ - Represents single dimension array of \u003c*Type*\u003e item type to be stored in or retrieved from a database. In SQL server single dimension array names as \u003c*DbType*\u003e__Array__.\n- __Sql__\u003c*ClrType*\u003e__RegularArray__ - Represents multiple dimensions array of \u003c*Type*\u003e item type to be stored in or retrieved from a database. In SQL server multiple dimensions array names as \u003c*DbType*\u003e__RegularArray__.\n\nThe following table shows the mapping of names in the assembly and names in the SQL Server.\n\n*ClrType* | *DbType*\n---|---\nBigInteger|HugeInt\nBinary|Binary\nBoolean|Bit\nByte|TinyInt\nComplex|Complex\nDateTime|DateTime\nDouble|DoubleFloat\nGradAngle|GradAngle\nGuid|Uid\nHourAngle|HourAngle\nInt16|SmallInt\nInt32|Int\nInt64|BigInt\nRange|Range\nLongRange|BigRange\nSexagesimalAngle|SexagesimalAngle\nSingle|SingleFloat\nString|String\n\nTo deploy the assembly on an MSSQL server, use the sqlclrdu.exe utility described below. For example,\n```\n\u003esqlclrdu.exe create -permission:unsafe -script:script.sql -schema:pwrlib -connection:\"Data Source=MASTER\\MSSQLSERVER2016;Initial Catalog=AdventureWorks2016;Integrated Security=True;Connect Timeout=15;\" \"PowerLib.System.Data.SqlTypes.dll\"\n```\nDependent assemblies without sqlclr contents are installed with the -invisible option. Assemblies from GAC deploy by strong assembly name with -strong option. For example,\n```\n\u003esqlclrdu.exe create -invisible -strong -script:test.sql \"System.Runtime.Serialization, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089\"\n```\n\nContinued...\n\n---\n## PowerLib.SqlServer\n\nContains more than a thousand functions that integrates into the SQL server. All functions can be divided into several categories: binary type manipulation, text manipulation (regular expression support), compression, cryptography, xml type manipulation (xpath query, xsl transformation, convert to and from json) and base types collections, single and multiple dimensions array support. All functions integrate into LINQ to SQL and EntityFramework.\n\nTo deploy the assembly on an MSSQL server, use the sqlclrdu.exe utility described below. For example,\n```\nsqlclrdu.exe create -permission:unsafe -script:script.sql -schema:pwrlib -map:\"PowerLib.System.Data.map\" -connection:\"Data Source=MASTER\\MSSQLSERVER2016;Initial Catalog=AdventureWorks2016;Integrated Security=True;Connect Timeout=15;\" \"PowerLib.SqlServer.dll\"\n```\nDependent assemblies without sqlclr contents are installed with the -invisible option. Assemblies from GAC deploy by strong assembly name with -strong option. For example,\n```\n\u003esqlclrdu.exe create -invisible -strong -script:test.sql \"System.Runtime.Serialization, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089\"\n```\n\nContinued...\n\n## PowerLib.SqlServer.Web\n\nContains functions for working with web services that integrates into the SQL server.\n\nFunctions for web queries have the following forms:\n\n__webQueryGet__\u003c*DataType*\u003e - function request web service and receive data of \u003c*DataType*\u003e type.\n\n__webQueryPut__\u003c*DataType*\u003e - function request web service and send data of \u003c*DataType*\u003e type.\n\n__webQueryPut__\u003c*DataType*\u003e__Get__\u003c*DataType*\u003e - function request web service, send data of \u003c*DataType*\u003e type and receive of \u003c*DataType*\u003e.\n\n__webQueryGet__\u003c*DataType*\u003e__Ext__ - stored procedure request web service and receive data of \u003c*DataType*\u003e type.\n\n__webQueryPut__\u003c*DataType*\u003e__Ext__ - stored procedure request web service and send data of \u003c*DataType*\u003e type.\n\n__webQueryPut__\u003c*DataType*\u003e__Get__\u003c*DataType*\u003e__Ext__ - stored procedure request web service, send data of \u003c*DataType*\u003e type and receive of \u003c*DataType*\u003e.\n\n\nwhere \u003c*DataType*\u003e = __Xml__ | __Text__ | __Binary__\n\nAlso, the following data conversion functions are defined in this assembly (schema __pwrlib__):\n\n__webHtmlDecode__,\n__webHtmlEncode__,\n__webUrlDecode__,\n__webUrlEncode__,\n__webUrlDecodeBinary__,\n__webUrlEncodeBinary__,\n__webDateTimeToString__,\n__webDateTimeParse__.\n\nWeb query example:\n```sql\ndeclare @html nvarchar(max);\ndeclare @headers_get pwrlib.NameValueCollection;\ndeclare @attrs_get pwrlib.NameValueCollection;\n--  NameValueCollection initialization\n--  Initialize collection response property names to retrieve (properties to request object prefixied by 'request:')\nset @attrs_get = pwrlib.nvCollCreate()\n  .AddItem('response:StatusCode', null)\n  .AddItem('response:CharacterSet', null)\n  .AddItem('response:LastModified', null)\n  .AddItem('response:Method', null)\n  .AddItem('response:Server', null)\n  .AddItem('response:ResponseUri', null)\n  .AddItem('response:ProtocolVersion', null)\n  .AddItem('response:StatusDescription', null);\n--  Request home page of wikipedia.org\nexecute pwrlib.webQueryGetTextExt N'http://www.wikipedia.org', N'GET', null, @headers_get output, @html output, @attrs_get output;\n--  Select results of query\nselect *\n  from pwrlib.nvCollEnumerate(@headers_get)\nunion\nselect *\n  from pwrlib.nvCollEnumerate(@attrs_get)\n--\ndeclare @headers_put pwrlib.NameValueCollection;\n--  NameValueCollection alternate initialization\nset @headers_put = pwrlib.nvCollAdd(pwrlib.nvCollCreate(), 'content-type', 'application/text;charset=utf-16');\n--  Store file on local storage in utf-16 encoding\nexecute pwrlib.webQueryPutTextExt N'file://e:\\WebStore\\wikipedia.org.html', N'PUT', @headers_put, @html, null, null;\n```\n---\n## PowerLib.SqlClr.Deploy\n\nA library that examines the specified assembly for sql clr objects and generates an SQL script for their registration, modification and deletion.\n\n---\n## PowerLib.SqlClr.Deploy.Utility\n\nThe sqlclrdu.exe utility is designed to deploy any sql clr assemblies on the MSSQL server.\n\n```\n\u003e sqlclrdu.exe\n\nMicrosoft SQL server CLR assembly deployment utility.\n\nsyntax:\n  sqlclrdu.exe \u003ccommand\u003e \u003coptions\u003e \u003cassembly\u003e\n\ncommands:\n  create - Create assembly on SQL server database.\n  alter - Alter assembly on SQL server database.\n  drop - Drop assembly on SQL server database.\n  manage - Manage database (-enable-clr, -trustworthy keys accepted).\n\noptions:\n  -assembly:\u003cassembly_name\u003e - Assembly name in SQL server.\n  -script:\u003cscript_file\u003e - SQL script file path.\n  -map:\u003cmap_file\u003e - Map referenced types to SQL Server database objects.\n  -encoding:\u003cscript_encoding\u003e - SQL script file encoding.\n  -connection:\u003cconnection_string\u003e - SQL server connection string.\n  -permission:[safe|ext_access|unsafe] - One of three different levels of security in which your code can run.\n  -owner:\u003cowner\u003e - Database user or role.\n  -schema:\u003cschema\u003e - Database schema.\n  -unchecked - Applied with ALTER ASSEMBLY command and add UNCHECKED DATA option.\n  -invisible - Only register assembly without its contents.\n  -append - Append to SQL script file.\n  -strong - Specifies that the assembly is defined by a strong name.\n  -enable-clr - Sets 'clr enabled' option for SQL server.\n  -trustworthy - Sets 'trustworthy' option for database.\n\ncomments:\n  If string values contain spaces, they must be enclosed in double quotes.\n  For example, -connection:\"Data Source = MASTER\\MSSQLSERVER2016;Initial Catalog = AdventureWorks2016; Integrated Security = True\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaseug%2Fpowerlib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvaseug%2Fpowerlib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvaseug%2Fpowerlib/lists"}