AltairOps.DynamicLibrary 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package AltairOps.DynamicLibrary --version 1.0.2
                    
NuGet\Install-Package AltairOps.DynamicLibrary -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AltairOps.DynamicLibrary" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AltairOps.DynamicLibrary" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="AltairOps.DynamicLibrary" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AltairOps.DynamicLibrary --version 1.0.2
                    
#r "nuget: AltairOps.DynamicLibrary, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AltairOps.DynamicLibrary@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AltairOps.DynamicLibrary&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=AltairOps.DynamicLibrary&version=1.0.2
                    
Install as a Cake Tool

Dynamic Library

This library contains a set of functions that can be used to filter, sort enumerables.

Nagivation

Usage

This examples contemplates the usage of the library having the following 'entity'.

List<TestEntity> EntityList =
	[
		new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Doe", Age = 25, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "Michael", LastName = "Johnson", Age = 30, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 18, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "Emily", LastName = "Davis", Age = 35, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "David", LastName = "Brown", Age = 50, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "Anna", LastName = "Taylor", Age = 43, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "James", LastName = "Anderson", Age = 65, CreatedDateUtc = DateTime.UtcNow },
		new TestEntity { Id = Guid.NewGuid(), Name = "Jane", LastName = "Smith", Age = 28, CreatedDateUtc = DateTime.UtcNow },
	];

Filtering

Filtering can be done using the ApplyFilter. <br/> The following example shows how to filter the list of entities to get only the ones with age greater than or equal to 65.

var query = EntityList.AsQueryable();
query = query.ApplyFilter(f => f.Age >= 65);

// Apply .ToList() to get the filtered list
var filteredList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "James", LastName = "Anderson", Age = 65, CreatedDateUtc = DateTime.UtcNow },
];
Filtering using the FilterModel

You can also use the FilterModel to filter the list of entities. <br/> The FilterModel accepts the following properties:

  • Field
    • The field to filter by
  • Value
    • The value to filter by
  • Operator
    • The operator to use in the filter

The FilterModel accepts the following operators:

  • Equal
  • NotEqual
  • GreaterThan
  • GreaterThanOrEqual
  • LessThan
  • LessThanOrEqual

The following example shows how to filter the list of entities to get only the ones with age greater than or equal to 65.

var query = EntityList.AsQueryable();

var model = new FilterModel<TestEntity>
{
	Field = "Age",
	Operator = FilterOperator.Equal,
	Value = "50"
};

query = query.ApplyFilter<TestEntity>(model);

// Apply the .ToList() to get the filtered list
var newList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "David", LastName = "Brown", Age = 50, CreatedDateUtc = DateTime.UtcNow },
];
Filtering using the Filters list in FilterModel.

You can also use the Filters list in the FilterModel to filter the list of entities. <br/> The Filters list accepts a list of FilterModel to filter the list of entities. <br/> The following example shows how to filter the list of entities to get only the ones with age greater than or equal to 50 and the name is "John".

var query = EntityList.AsQueryable();
var model = new FilterModel<TestEntity>
		{
			Operator = FilterOperator.And,
			Filters =
			[
				new FilterModel<TestEntity>
				{
					Field = "Age",
					Operator = FilterOperator.GreaterThanOrEqual,
					Value = " 50"
				},
				new FilterModel<TestEntity>
				{
					Field = "Name",
					Operator = FilterOperator.Equal,
					Value = "John"
				}
			]
		};

query = query.ApplyFilter(model);

// Apply the .ToList() to get the filtered list
var newList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
];

Sorting

Sorting can be done using the ApplySort. <br/> The following example shows how to sort the list of entities by the Age property in ascending order.

var query = EntityList.AsQueryable();
query = query.ApplySort(a => a.Age, Enums.SortingDirection.Ascending);

// Apply .ToList() to get the sorted list
var sortedList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 18, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Jane", LastName = "Smith", Age = 28, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Michael", LastName = "Johnson", Age = 30, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Emily", LastName = "Davis", Age = 35, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Anna", LastName = "Taylor", Age = 43, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "David", LastName = "Brown", Age = 50, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "James", LastName = "Anderson", Age = 65, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
];
Sorting using the OrderByModel

Filtering can also be done using the OrderByModel. <br/> The OrderByModel accepts the following properties:

  • Field
    • The field to sort by
  • Direction
    • The direction of the sorting
  • UseString
    • If desire, you an also sent a string with the field and direction to sort by, e.g.: "Age asc"
var query = EntityList.AsQueryable();
var model = new OrderByModel<TestEntity>
{
	UseString = "Age asc",
};

query = query.ApplySort(model);

// Apply .ToList() to get the sorted list
var sortedList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 18, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Jane", LastName = "Smith", Age = 28, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Michael", LastName = "Johnson", Age = 30, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Emily", LastName = "Davis", Age = 35, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Anna", LastName = "Taylor", Age = 43, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "David", LastName = "Brown", Age = 50, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "James", LastName = "Anderson", Age = 65, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
];

Note: If the UseString property is not present in the Entity, the library will throw an exception.

Or also use the Field attribute in the OrderByModel:

var query = EntityList.AsQueryable();
var model = new OrderByModel<TestEntity>
{
	Field = "Age",
	Direction = SortingDirection.Ascending,
};

query = query.ApplySort(model);

// Apply .ToList() to get the sorted list
var sortedList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 18, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Jane", LastName = "Smith", Age = 28, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Michael", LastName = "Johnson", Age = 30, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Emily", LastName = "Davis", Age = 35, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Anna", LastName = "Taylor", Age = 43, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "David", LastName = "Brown", Age = 50, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "James", LastName = "Anderson", Age = 65, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
];

Note: If the Field property is not present in the Entity, the library will throw an exception.

Pagination

Pagination can be done using the ApplyPagination. It uses the OrderByModel.<br/> The following example shows how to paginate the list of entities to get only the first 3 elements.

var query = EntityList.AsQueryable();
var model = new PaginationModel
{
	Page = 1,
	PageSize = 3,
};

query = query.ApplyPagination(model);

// Apply .ToList() to get the paginated list
var paginatedList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Doe", Age = 25, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "Michael", LastName = "Johnson", Age = 30, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 18, CreatedDateUtc = DateTime.UtcNow },
];

Using the QueryResult

The QueryResult model can be used to return a list and it's count of an specified collection. <br/>

The following example shows how to use the QueryResult model to return the list of entities and it's count.

var query = TestEntity.EntityList.AsQueryable();

query = query.ApplyFilter<TestEntity>(a => a.Name == "John");
query = query.ApplySort<TestEntity>(a => a.Age, SortingDirection.Descending);
query = query.ApplyPagination<TestEntity>(new PaginationModel
{
	PageSize = 3
});

// Apply the .ToList() to get the filtered, sorted and paginated list
var newList = query.ToList();

Returns:

[
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Moore", Age = 80, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Thomas", Age = 55, CreatedDateUtc = DateTime.UtcNow },
	new TestEntity { Id = Guid.NewGuid(), Name = "John", LastName = "Wilson", Age = 25, CreatedDateUtc = DateTime.UtcNow },
];
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 179 2/7/2025
1.0.5 149 2/7/2025
1.0.4 148 2/7/2025
1.0.3 145 2/7/2025
1.0.2 154 2/6/2025
1.0.1 145 2/6/2025
1.0.0 153 2/1/2025