Add Some New Extensions Methods ...
This commit is contained in:
@@ -624,6 +624,21 @@ namespace xCommons.Extensions
|
||||
{
|
||||
return !source.IsNull() && source.Count() > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Select Async ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <typeparam name="TSource"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static async Task<IEnumerable<TResult>> SelectAsync<TSource, TResult>(
|
||||
this IEnumerable<TSource> source, Func<TSource, Task<TResult>> method
|
||||
)
|
||||
{
|
||||
return await Task.WhenAll(source.Select(async s => await method(s)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a Collection item ...
|
||||
@@ -919,6 +934,58 @@ namespace xCommons.Extensions
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Summarize a Text ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="maxAllowedLength"></param>
|
||||
/// <param name="endsWith"></param>
|
||||
/// <returns></returns>
|
||||
public static string SummarizeContent(
|
||||
this string source,
|
||||
int maxAllowedLength = 0,
|
||||
string endsWith = ""
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = string.Empty;
|
||||
if (source.IsNullOrEmpty() || maxAllowedLength <= 0)
|
||||
{
|
||||
//
|
||||
result = source;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Pattern of Links ...
|
||||
var pattern = @"(?:[!]\[(.*?)\]\(.*?\))";
|
||||
|
||||
//
|
||||
// Apply Summarization ...
|
||||
|
||||
//
|
||||
// Replace Markdown Links using RegExp ...
|
||||
result = Regex.Replace(source, pattern, "");
|
||||
|
||||
//
|
||||
// Do Summarization if Length bigger than MaxLength ...
|
||||
if (result.Length > maxAllowedLength)
|
||||
{
|
||||
result = result.Substring(0, maxAllowedLength);
|
||||
}
|
||||
|
||||
//
|
||||
// Apply EndsWith if Provided ...
|
||||
if (!endsWith.IsNullOrEmpty() &&
|
||||
!result.EndsWith(endsWith))
|
||||
{
|
||||
result += endsWith;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check an string is a Valid Representation of PhoneNumber ...
|
||||
/// </summary>
|
||||
@@ -1080,6 +1147,49 @@ namespace xCommons.Extensions
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a List String Representation to GUid List ...
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="separator"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<Guid> ParseListGuid(
|
||||
this string list,
|
||||
char? separator = null
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = new List<Guid>();
|
||||
|
||||
//
|
||||
if (!separator.HasValue)
|
||||
{
|
||||
separator = CommonConstants.DEFAULT_LIST_SEPERATOR;
|
||||
}
|
||||
|
||||
//
|
||||
if (list.IsNullOrEmpty())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
var items = list.Split(separator.Value);
|
||||
items.ToList().ForEach(i =>
|
||||
{
|
||||
//
|
||||
if (!i.IsNullOrEmpty() && i.IsGuid() && !i.IsDefaultGuid())
|
||||
{
|
||||
//
|
||||
var gID = new Guid(i);
|
||||
result.Add(gID);
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert a List to List String ...
|
||||
|
||||
Reference in New Issue
Block a user