This commit is contained in:
FH 2022-02-04 08:39:06 +01:00
parent cc1dd46cc9
commit ef688cca2e
9 changed files with 100 additions and 130 deletions

View file

@ -4,12 +4,27 @@
// Created : 27-08-2016
//
// Last Modified By : Frede H.
// Last Modified On : 2021-02-24
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="ExtensionsEx.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary></summary>
// <summary>
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -18,7 +33,7 @@ using System.Collections.Generic;
namespace FCS.Lib
{
/// <summary>
/// Class ExtensionsEx.
/// Class ExtensionsEx.
/// </summary>
public static class ExtensionsEx
{

View file

@ -4,16 +4,16 @@
// Created : 2020-07-01
//
// Last Modified By : FH
// Last Modified On : 2021-02-24
// Last Modified On : 01-09-2022
// ***********************************************************************
// <copyright file="Generators.cs" company="Frede Hundewadt">
// <copyright file="Generators.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// derived from https://sourceforge.net/projects/shorturl-dotnet
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
// Partly derived from https://sourceforge.net/projects/shorturl-dotnet/
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
@ -26,7 +26,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -37,8 +37,8 @@ using System.Security.Cryptography;
namespace FCS.Lib
{
/// <summary>
/// Class Generators
/// <remarks>generates varioous kinds of random strings. </remarks>
/// Class Generators
/// <remarks>generates varioous kinds of random strings. </remarks>
/// </summary>
public static class Generators
{
@ -56,7 +56,7 @@ namespace FCS.Lib
/// </summary>
/// <param name="length">The lengt h.</param>
/// <returns>System.String.</returns>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet </remarks>
/// <remarks></remarks>
public static string ShortUrlGenerator(int length)
{
const string charsLower = "cdfghjkmnpqrstvwxyz";
@ -129,8 +129,7 @@ namespace FCS.Lib
// If we processed the last character in this group, start over.
if (lastCharIdx == 0)
{
charsLeftInGroup[nextGroupIdx] =
charGroups[nextGroupIdx].Length;
charsLeftInGroup[nextGroupIdx] = charGroups[nextGroupIdx].Length;
}
// There are more unprocessed characters left.
else
@ -297,7 +296,7 @@ namespace FCS.Lib
/// Randoms the seed.
/// </summary>
/// <returns>Random.</returns>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/</remarks>
/// <remarks>derived from https://sourceforge.net/projects/shorturl-dotnet/ </remarks>
public static Random RandomSeed()
{
// As the default randomizer is based on the current time

View file

@ -4,12 +4,11 @@
// Created : 03-10-2015
//
// Last Modified By : FH
// Last Modified On : 2021-03-27
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="IRepositoryAsync.cs" company="FCS">
// <copyright file="IAsyncReadonlyRepo.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -25,7 +24,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -37,7 +36,7 @@ using System.Threading.Tasks;
namespace FCS.Lib
{
/// <summary>
/// Interface IRepositoryAsync
/// Interface IRepositoryAsync
/// </summary>
/// <typeparam name="TEntity">The type of the t entity.</typeparam>
public interface IAsyncReadonlyRepo<TEntity> where TEntity : class

View file

@ -4,12 +4,11 @@
// Created : 05-13-2020
//
// Last Modified By : FH
// Last Modified On : 2021-02-24
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="IRepository.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -25,13 +24,13 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
namespace FCS.Lib
{
/// <summary>
/// Interface IRepository
/// Interface IRepository
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="TKey">The type of the TKey.</typeparam>

View file

@ -4,12 +4,11 @@
// Created : 03-10-2015
//
// Last Modified By : FH
// Last Modified On : 2021-11-13
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="IRepositoryEx.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -25,7 +24,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -36,7 +35,7 @@ using System.Threading.Tasks;
namespace FCS.Lib
{
/// <summary>
/// Interface IRepositoryEx
/// Interface IRepositoryEx
/// </summary>
/// <typeparam name="TEntity">The type of the t entity</typeparam>
public interface IRepositoryEx<TEntity> where TEntity : class

View file

@ -4,12 +4,11 @@
// Created : 27-08-2016
//
// Last Modified By : Frede H.
// Last Modified On : 2021-02-24
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="Mogrifiers.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -25,7 +24,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -40,7 +39,7 @@ using System.Text.RegularExpressions;
namespace FCS.Lib
{
/// <summary>
/// Class Converters
/// Class Converters
/// </summary>
public static class Mogrifiers
{
@ -119,7 +118,7 @@ namespace FCS.Lib
/// <returns>T.</returns>
public static T IntToEnum<T>(int value)
{
return (T)Enum.ToObject(typeof(T), value);
return (T) Enum.ToObject(typeof(T), value);
}
/// <summary>
@ -171,7 +170,7 @@ namespace FCS.Lib
{
var empty = string.Empty;
if (list == null) return empty;
var enumerator = (IEnumerator)list.GetType().GetMethod("GetEnumerator")?.Invoke(list, null);
var enumerator = (IEnumerator) list.GetType().GetMethod("GetEnumerator")?.Invoke(list, null);
while (enumerator != null && enumerator.MoveNext())
if (enumerator.Current != null)
empty = string.Concat(empty, enumerator.Current.ToString(), delimiter);
@ -228,8 +227,8 @@ namespace FCS.Lib
return
!decimal.TryParse(inString.Replace(",", "").Replace(".", ""), NumberStyles.Number,
CultureInfo.InvariantCulture, out var num)
? null
: decimal.Divide(num, new decimal((long)100));
? (decimal?) null
: decimal.Divide(num, new decimal((long) 100));
}
/// <summary>
@ -240,7 +239,7 @@ namespace FCS.Lib
/// <returns>T.</returns>
public static T StringToEnum<T>(string value)
{
return (T)Enum.Parse(typeof(T), value, true);
return (T) Enum.Parse(typeof(T), value, true);
}
/// <summary>
@ -263,11 +262,6 @@ namespace FCS.Lib
/// <returns>List&lt;T&gt;.</returns>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
/// <exception cref="ArgumentNullException">delimiter</exception>
/// <exception cref="ArgumentNullException">value</exception>
public static List<T> StringToList<T>(string value, string delimiter)
{
if (string.IsNullOrEmpty(value)) throw new ArgumentNullException(nameof(value));
@ -282,16 +276,16 @@ namespace FCS.Lib
var upperInvariant = o.ToUpperInvariant();
if (string.CompareOrdinal(upperInvariant, "system.string") == 0)
{
ts.Add((T)Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
ts.Add((T) Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
}
else if (string.CompareOrdinal(upperInvariant, "system.int32") == 0)
{
ts.Add((T)Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
ts.Add((T) Convert.ChangeType(str, typeof(T), CultureInfo.InvariantCulture));
}
else if (string.CompareOrdinal(upperInvariant, "system.guid") == 0)
{
var guid = new Guid(str);
ts.Add((T)Convert.ChangeType(guid, typeof(T), CultureInfo.InvariantCulture));
ts.Add((T) Convert.ChangeType(guid, typeof(T), CultureInfo.InvariantCulture));
}
}
@ -338,12 +332,12 @@ namespace FCS.Lib
var dt = DateTime.UtcNow.ToString("yy MM dd HH MM ss");
var sb = new StringBuilder();
var dts = dt.Split(' ');
sb.Append((char)int.Parse(dts[0]) + 65);
sb.Append((char)int.Parse(dts[1]) + 65);
sb.Append((char)int.Parse(dts[2]) + 97);
sb.Append((char)int.Parse(dts[3]) + 65);
sb.Append((char)int.Parse(dts[4]) + 97);
sb.Append((char)int.Parse(dts[5]) + 97);
sb.Append((char) int.Parse(dts[0]) + 65);
sb.Append((char) int.Parse(dts[1]) + 65);
sb.Append((char) int.Parse(dts[2]) + 97);
sb.Append((char) int.Parse(dts[3]) + 65);
sb.Append((char) int.Parse(dts[4]) + 97);
sb.Append((char) int.Parse(dts[5]) + 97);
return sb.ToString();
}

View file

@ -1,16 +1,14 @@
// ***********************************************************************
// Assembly : FCS.Lib
// Author : FH
// Created : 2020-07-01
// Created : 01-01-2022
//
// Last Modified By : FH
// Last Modified On : 2021-02-24
// Last Modified On : 12-31-2021
// ***********************************************************************
// <copyright file="QueryHelper.cs" company="Frede Hundewadt">
// Copyright © FCS 2015-2022
// <copyright file="QueryHelper.cs" company="">
// Copyright © 2021
// </copyright>
// <summary>
// Implementation of https://stackoverflow.com/a/45761590
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -26,7 +24,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -41,63 +39,40 @@ namespace FCS.Lib
/// </summary>
public static class QueryHelper
{
/// <summary>
/// Orders the by.
/// </summary>
/// <typeparam name="TModel">The type of the t model.</typeparam>
/// <param name="q">The q.</param>
/// <param name="name">The name.</param>
/// <param name="desc">if set to <c>true</c> [desc].</param>
/// <returns>IQueryable&lt;TModel&gt;.</returns>
public static IQueryable<TModel> OrderBy<TModel>(this IQueryable<TModel> q, string name, bool desc)
// https://stackoverflow.com/a/45761590
public static IQueryable<TModel> OrderBy<TModel>
(this IQueryable<TModel> q, string name, bool desc)
{
var entityType = typeof(TModel);
var p = entityType.GetProperty(name);
var m = typeof(QueryHelper).GetMethod("OrderByProperty")?.MakeGenericMethod(entityType, p.PropertyType);
return (IQueryable<TModel>)m.Invoke(null, new object[] { q, p, desc });
var m = typeof(QueryHelper)
.GetMethod("OrderByProperty")
?.MakeGenericMethod(entityType, p.PropertyType);
return(IQueryable<TModel>) m.Invoke(null, new object[] {
q, p , desc });
}
/// <summary>
/// Thens the by.
/// </summary>
/// <typeparam name="TModel">The type of the t model.</typeparam>
/// <param name="q">The q.</param>
/// <param name="name">The name.</param>
/// <param name="desc">if set to <c>true</c> [desc].</param>
/// <returns>IQueryable&lt;TModel&gt;.</returns>
public static IQueryable<TModel> ThenBy<TModel>(this IQueryable<TModel> q, string name, bool desc)
public static IQueryable<TModel> ThenBy<TModel>
(this IQueryable<TModel> q, string name, bool desc)
{
var entityType = typeof(TModel);
var p = entityType.GetProperty(name);
var m = typeof(QueryHelper).GetMethod("OrderByProperty")?.MakeGenericMethod(entityType, p.PropertyType);
return (IQueryable<TModel>)m.Invoke(null, new object[] { q, p, desc });
var m = typeof(QueryHelper)
.GetMethod("OrderByProperty")
?.MakeGenericMethod(entityType, p.PropertyType);
return(IQueryable<TModel>) m.Invoke(null, new object[] {
q, p , desc });
}
/// <summary>
/// Orders the by property.
/// </summary>
/// <typeparam name="TModel">The type of the t model.</typeparam>
/// <typeparam name="TRet">The type of the t ret.</typeparam>
/// <param name="q">The q.</param>
/// <param name="p">The p.</param>
/// <param name="desc">if set to <c>true</c> [desc].</param>
/// <returns>IQueryable&lt;TModel&gt;.</returns>
public static IQueryable<TModel> OrderByProperty<TModel, TRet>(IQueryable<TModel> q, PropertyInfo p, bool desc)
public static IQueryable<TModel> OrderByProperty<TModel, TRet>
(IQueryable<TModel> q, PropertyInfo p, bool desc)
{
var pe = Expression.Parameter(typeof(TModel));
Expression se = Expression.Convert(Expression.Property(pe, p), typeof(object));
var exp = Expression.Lambda<Func<TModel, TRet>>(se, pe);
return desc ? q.OrderByDescending(exp) : q.OrderBy(exp);
}
}
}
}}

View file

@ -4,13 +4,16 @@
// Created : 2020-07-01
//
// Last Modified By : FH
// Last Modified On : 2021-02-24
// Last Modified On : 01-09-2022
// ***********************************************************************
// <copyright file="Squid.cs" company="Frede Hundewadt">
// <copyright file="Squid.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
// Derived from https:github.com/csharpvitamins/CSharpVitamins.ShortGuid
// Derived from https://www.madskristensen.net/blog/A-shorter-and-URL-friendly-GUID
// AGPL https://www.gnu.org/licenses/agpl-3.0.en.html
// Functional similar to https:github.com/csharpvitamins/CSharpVitamins.ShortGuid
//
// Part of FCS.Lib - a set of utilities for C# - pieced together from fragments
// Copyright (C) 2021 FCS
//
@ -26,7 +29,6 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
using System;
@ -35,19 +37,15 @@ using System.Diagnostics;
namespace FCS.Lib
{
/// <summary>
/// A wrapper for handling URL-safe Base64 encoded globally unique identifiers (GUID).
/// A wrapper for unique identifiers (GUID).
/// </summary>
/// <remarks>
/// Special characters are replaced (/, +) or removed (==).
/// Derived from https:github.com/csharpvitamins/CSharpVitamins.ShortGuid
/// </remarks>
/// <remarks>Special characters are replaced (/, +) or removed (==).</remarks>
[DebuggerDisplay("{" + nameof(Value) + "}")]
public readonly struct Squid : IEquatable<Squid>
{
/// <summary>
/// A read-only object of the Squid struct.
/// Value is guaranteed to be all zeroes.
/// Equivalent to Guid.Empty" />.
/// Equivalent to <see cref="Guid.Empty" />.
/// </summary>
public static readonly Squid Empty = new(Guid.Empty);
@ -117,7 +115,7 @@ namespace FCS.Lib
}
/// <summary>
/// Returns the hash code for the underlying <see cref="System.Guid" />.
/// Returns the hash code for the guid <see cref="System.Guid" />.
/// </summary>
/// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns>
public override int GetHashCode()
@ -129,18 +127,16 @@ namespace FCS.Lib
}
/// <summary>
/// Initialises a new object of the Squid using Guid.NewGuid()" />.
/// Initialises a new Squid using <see cref="Guid.NewGuid()" />.
/// </summary>
/// <returns>New Squid object</returns>
public static Squid NewGuid()
{
return new Squid(Guid.NewGuid());
return new(Guid.NewGuid());
}
/// <summary>
/// Encode string as a new Squid encoded string.
/// The encoding is similar to Base64 with
/// non-URL safe characters replaced, and padding removed.
/// Encode string as a new Squid string.
/// </summary>
/// <param name="value">A valid <see cref="System.Guid" />.Tostring().</param>
/// <returns>A 22 character URL-safe Base64 string.</returns>
@ -152,8 +148,6 @@ namespace FCS.Lib
/// <summary>
/// Encode a <see cref="System.Guid" /> object to Squid.
/// The encoding is similar to Base64 with
/// non-URL safe characters replaced, and padding removed.
/// </summary>
/// <param name="obj">A valid <see cref="System.Guid" /> object.</param>
/// <returns>A 22 character URL-safe Base64 string.</returns>
@ -231,8 +225,7 @@ namespace FCS.Lib
}
/// <summary>
/// Tries to parse the given string value and
/// outputs the <see cref="Squid" /> object.
/// Tries to parse the given string value and output the <see cref="Squid" /> object.
/// </summary>
/// <param name="value">The Squid encoded string or string representation of a Guid.</param>
/// <param name="obj">A new <see cref="Squid" /> object from the parsed string.</param>
@ -258,8 +251,7 @@ namespace FCS.Lib
}
/// <summary>
/// Tries to parse the string value and
/// outputs the underlying <see cref="System.Guid" /> object.
/// Tries to parse the string value and outputs the underlying <see cref="System.Guid" /> object.
/// </summary>
/// <param name="value">The Squid encoded string or string representation of a Guid.</param>
/// <param name="obj">A new <see cref="System.Guid" /> object from the parsed string.</param>
@ -278,8 +270,6 @@ namespace FCS.Lib
return false;
}
#region Operators
/// <summary>
/// Determines if both Squid objects have the same
/// underlying <see cref="System.Guid" /> value.
@ -397,6 +387,5 @@ namespace FCS.Lib
return oGuid == Guid.Empty ? Empty : new Squid(oGuid);
}
#endregion
}
}

View file

@ -4,9 +4,9 @@
// Created : 2020-09-09
//
// Last Modified By : FH
// Last Modified On : 2021-02-24
// Last Modified On : 01-09-2022
// ***********************************************************************
// <copyright file="StringOptions.cs" company="Frede Hundewadt">
// <copyright file="StringOptions.cs" company="FCS">
// Copyright © FCS 2015-2022
// </copyright>
// <summary>
@ -25,13 +25,14 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// </summary>
// ***********************************************************************
namespace FCS.Lib
{
/// <summary>
/// Class StringOptions.
/// Class StringOptions.
/// </summary>
public class StringOptions
{