2024-12-06 12:36:58 +01:00
|
|
|
|
using BS.Shared.Interface;
|
|
|
|
|
|
using System;
|
2016-06-27 01:45:38 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BS.Shared.Extensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class StringExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static bool ContainsAll(this string pString, IEnumerable<string> pToCheck)
|
|
|
|
|
|
{
|
|
|
|
|
|
string lLow = pString.ToLower();
|
|
|
|
|
|
foreach (var iS in pToCheck)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!lLow.Contains(iS.Trim().ToLower()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-14 15:20:37 +02:00
|
|
|
|
public static bool IsNotNullOrEmpty(this string pString)
|
|
|
|
|
|
=> !IsNullOrEmpty(pString);
|
|
|
|
|
|
|
2016-06-27 01:45:38 +02:00
|
|
|
|
public static bool IsNullOrEmpty(this string pString)
|
|
|
|
|
|
{
|
|
|
|
|
|
return String.IsNullOrEmpty(pString);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static List<string> Split(this string pString, string pSeparator)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(pString == null)
|
|
|
|
|
|
return new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
return pString.Split(new[] { pSeparator }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<KeyValuePair<string, string>> SplitToKeyValuePairList(this string pString, string pSeparator1, string pSeperator2)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(pString == null)
|
|
|
|
|
|
return new KeyValuePair<string, string>[0];
|
|
|
|
|
|
|
|
|
|
|
|
var preResult = pString.Split(pSeparator1);
|
|
|
|
|
|
|
|
|
|
|
|
return preResult.Select(pair => new KeyValuePair<string, string>(pair.Split(pSeperator2)[0], pair.Split(pSeperator2)[1])).ToList();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetRecurrenceInfoAttribute(this string recurrenceInfo, string attribute)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var reader = XmlReader.Create(new StringReader(recurrenceInfo)))
|
|
|
|
|
|
{
|
|
|
|
|
|
reader.ReadToFollowing("RecurrenceInfo");
|
|
|
|
|
|
reader.MoveToAttribute(attribute);
|
|
|
|
|
|
|
|
|
|
|
|
return reader.Value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static T GetValueFromDescription<T>(this string description)
|
|
|
|
|
|
{
|
|
|
|
|
|
var type = typeof(T);
|
|
|
|
|
|
if (!type.IsEnum) throw new InvalidOperationException();
|
|
|
|
|
|
foreach (var field in type.GetFields())
|
|
|
|
|
|
{
|
|
|
|
|
|
var attribute = Attribute.GetCustomAttribute(field,
|
|
|
|
|
|
typeof(DescriptionAttribute)) as DescriptionAttribute;
|
|
|
|
|
|
if (attribute != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (attribute.Description == description)
|
|
|
|
|
|
return (T)field.GetValue(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (field.Name == description)
|
|
|
|
|
|
return (T)field.GetValue(null);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
throw new ArgumentException("Not found.", "description");
|
|
|
|
|
|
}
|
2023-03-14 16:12:52 +01:00
|
|
|
|
|
|
|
|
|
|
public static string RemoveUppercaseEsszett(this string pString)
|
|
|
|
|
|
{
|
|
|
|
|
|
return pString?.Replace("ẞ", "ß");
|
|
|
|
|
|
}
|
2024-11-22 16:30:43 +01:00
|
|
|
|
|
2024-12-06 11:40:53 +01:00
|
|
|
|
public static bool IsNotNullOrWhiteSpace(this string pString)
|
|
|
|
|
|
=> !pString.IsNullOrWhiteSpace();
|
|
|
|
|
|
public static bool IsNullOrWhiteSpace(this string str)
|
|
|
|
|
|
=> string.IsNullOrEmpty(str);
|
2024-11-22 16:30:43 +01:00
|
|
|
|
public static string ToNullIfEmpty(this string str)
|
2024-12-06 11:40:53 +01:00
|
|
|
|
=> str.IsNullOrWhiteSpace() ? null : str;
|
2024-11-22 16:30:43 +01:00
|
|
|
|
|
|
|
|
|
|
public static string ToFormatFollows(this string str1, string str2, char seperator = ' ')
|
|
|
|
|
|
{
|
|
|
|
|
|
str1 = str1.ToNullIfEmpty();
|
|
|
|
|
|
str2 = str2.ToNullIfEmpty();
|
|
|
|
|
|
|
|
|
|
|
|
var rtn = str1;
|
|
|
|
|
|
|
|
|
|
|
|
if(str2 is string)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (rtn is string)
|
|
|
|
|
|
rtn += seperator;
|
|
|
|
|
|
|
|
|
|
|
|
rtn += str2;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
|
|
}
|
2024-12-06 12:36:58 +01:00
|
|
|
|
|
|
|
|
|
|
public static bool AreAllTheSame(this IEnumerable<string> list)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (list is null || !list.Any())
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
string init = list.First();
|
|
|
|
|
|
foreach (var str in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (str != init)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string SenderAddressToString(this IInvoiceBase invoiceBase)
|
|
|
|
|
|
=> $"{invoiceBase.SenderStreet}, {invoiceBase.SenderTown}, {invoiceBase.SenderPostCode}";
|
2016-06-27 01:45:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|