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;

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;
@ -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

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;

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,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>
// ***********************************************************************
namespace FCS.Lib

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;

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;
@ -228,7 +227,7 @@ namespace FCS.Lib
return
!decimal.TryParse(inString.Replace(",", "").Replace(".", ""), NumberStyles.Number,
CultureInfo.InvariantCulture, out var num)
? null
? (decimal?) null
: decimal.Divide(num, new decimal((long) 100));
}
@ -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));

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,6 +25,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>
// ***********************************************************************