Class CollectionExtension
Extensions for collections.
Inheritance
Inherited Members
Namespace: StoneCo.Framework.Extension
Assembly: cs.temp.dll.dll
Syntax
public static class CollectionExtension
Methods
GetInLineConcat(List<String>, String)
Concatenates a collection of strings into a single string using the given delimiter.
If it is empty or is returning an empty string.
Declaration
public static string GetInLineConcat(this List<string> value, string delimiter = "")
Parameters
Type | Name | Description |
---|---|---|
List<System.String> | value | Collection with the values that will be concatenated. |
System.String | delimiter | Delimiter that will separate the values within the list. |
Returns
Type | Description |
---|---|
System.String | A single value concatenated with the supplied delimiter. |
Examples
IEnumerable<string> value = new List<string>() { "Framework", "StoneCo", "2.0" };
var concatenatedValue = value.GetInLineConcat(" | ");
The result is **Framework | StoneCo | 2.0.
ToInlineConcat(IEnumerable<String>, String)
Concatenate string list on single string using one delimiter. If list not contains items, the return is string empty.
Declaration
public static string ToInlineConcat(this IEnumerable<string> value, string delimiter = "")
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<System.String> | value | String list with items to concatenate. |
System.String | delimiter | String delimiter to separate items on string. |
Returns
Type | Description |
---|---|
System.String | Single string with concatenating the items or empty. |
Examples
var stringList = new List<string> { "Stone Co", "Transaction", "Repository" };
var stringConcatenated = stringList.ToInlineConcat(" | ");
ToPagedList<TSource, TKey>(IQueryable<TSource>, Expression<Func<TSource, TKey>>, Int32, Int32, Boolean)
Get object of type PagedList<T> from IQueryable.
Declaration
public static PagedList<TSource> ToPagedList<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> order, int page = 1, int itemsPerPage = 100, bool orderedAsc = true)
Parameters
Type | Name | Description |
---|---|---|
IQueryable<TSource> | source | The collection to be paginated. |
Expression<System.Func<TSource, TKey>> | order | Expression with the field that should be paginated. |
System.Int32 | page | Page number of items. |
System.Int32 | itemsPerPage | Total of items per page. |
System.Boolean | orderedAsc | Indicating the ordination. If value true the order is ascending else value false the order is descending. |
Returns
Type | Description |
---|---|
PagedList<TSource> | Result of paginated collection. |
Type Parameters
Name | Description |
---|---|
TSource | The type of the data in the data source. |
TKey | The type of the field in the data source. |
Examples
Foo class used in this example.
public class Foo
{
public int Id { get; private set; }
public string Name { get; private set; }
public Foo(string name) => Name = name;
}
Creating a List of Foo class and converting in IQueryable.
var foo = new Foo("Stone Co");
var fooList = new List<Foo> { foo };
var query = fooList.AsQueryable();
Sample of expression of order parameter.
Expression<Func<Foo, int>> order = it => it.Id;
Bar class used in this full example.
public class Bar
{
public PagedList<Foo> GetFoo() => GetFooRepository(1, 1);
public PagedList<Foo> GetFooRepository(int page, int itemsPerPage)
{
var foo1 = new Foo("Stone Co");
var foo2 = new Foo("Stone");
var foo3 = new Foo("Foo");
var fooList = new List<Foo> { foo1, foo2, foo3 };
var query = fooList.AsQueryable();
return query.ToPagedList(it => it.Name, page, itemsPerPage);
}
}
Exceptions
Type | Condition |
---|---|
System.ArgumentException | If page is less than 1, an exception is thrown with message |
System.ArgumentException | If itemsPerPage is less than 1, an exception is thrown with message |