* Added integration addon wit WTelegramBot (WIP)
* Added some extensions methods * Refactored Result behaviour * Added missing exception messages * Removed telegrator-specific host builder (obsolete) * Code cleanup and bug fixes
This commit is contained in:
@@ -6,3 +6,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
[assembly: SuppressMessage("Style", "IDE0090")]
|
||||
[assembly: SuppressMessage("Roslynator", "RCS1037")]
|
||||
|
||||
@@ -112,7 +112,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
||||
{
|
||||
try
|
||||
{
|
||||
PrimaryConstructorBaseTypeSyntax primaryConstructor = (PrimaryConstructorBaseTypeSyntax)classDeclaration.BaseList.Types.ElementAt(0);
|
||||
PrimaryConstructorBaseTypeSyntax primaryConstructor = (PrimaryConstructorBaseTypeSyntax)classDeclaration.BaseList.Types[0];
|
||||
MethodDeclarationSyntax genExtension = GeneratedExtensionsMethod(classDeclaration, classDeclaration.ParameterList, primaryConstructor.ArgumentList, targeter);
|
||||
extensions.Add(genExtension);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ public class ImplicitHandlerBuilderExtensionsGenerator : IIncrementalGenerator
|
||||
if (targeters.TryGetValue(classDeclaration.Identifier.ValueText, out MethodDeclarationSyntax targeter))
|
||||
return targeter;
|
||||
|
||||
if (classDeclaration.BaseList != null && targeters.TryGetValue(classDeclaration.BaseList.Types.ElementAt(0).Type.ToString(), out targeter))
|
||||
if (classDeclaration.BaseList != null && targeters.TryGetValue(classDeclaration.BaseList.Types[0].Type.ToString(), out targeter))
|
||||
return targeter;
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,64 +1,63 @@
|
||||
namespace Telegrator.RoslynGenerators.RoslynExtensions
|
||||
namespace Telegrator.RoslynGenerators.RoslynExtensions;
|
||||
|
||||
public static class CollectionsExtensions
|
||||
{
|
||||
public static class CollectionsExtensions
|
||||
public static IEnumerable<TSource> Combine<TSource>(params IEnumerable<TSource>[] collections)
|
||||
=> collections.SelectMany(x => x);
|
||||
|
||||
public static IEnumerable<TSource> IntersectBy<TSource, TValue>(this IEnumerable<TSource> first, IEnumerable<TValue> second, Func<TSource, TValue> selector)
|
||||
{
|
||||
public static IEnumerable<TSource> Combine<TSource>(params IEnumerable<TSource>[] collections)
|
||||
=> collections.SelectMany(x => x);
|
||||
|
||||
public static IEnumerable<TSource> IntersectBy<TSource, TValue>(this IEnumerable<TSource> first, IEnumerable<TValue> second, Func<TSource, TValue> selector)
|
||||
foreach (TSource item in first)
|
||||
{
|
||||
foreach (TSource item in first)
|
||||
{
|
||||
TValue value = selector(item);
|
||||
if (second.Contains(value))
|
||||
yield return item;
|
||||
}
|
||||
TValue value = selector(item);
|
||||
if (second.Contains(value))
|
||||
yield return item;
|
||||
}
|
||||
|
||||
public static IList<TValue> UnionAdd<TValue>(this IList<TValue> source, IEnumerable<TValue> toUnion, IEqualityComparer<TValue> comparer)
|
||||
{
|
||||
foreach (TValue toUnionValue in toUnion)
|
||||
{
|
||||
if (!source.Contains(toUnionValue, comparer))
|
||||
source.Add(toUnionValue);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
public static void UnionAdd<TSource>(this ICollection<TSource> collection, IEnumerable<TSource> target)
|
||||
{
|
||||
foreach (TSource item in target)
|
||||
{
|
||||
if (!collection.Contains(item))
|
||||
collection.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnionAdd<TSource>(this SortedList<TSource, TSource> collection, IEnumerable<TSource> target)
|
||||
{
|
||||
foreach (TSource item in target)
|
||||
{
|
||||
if (!collection.Values.Contains(item))
|
||||
collection.Add(item, item);
|
||||
}
|
||||
}
|
||||
|
||||
public static int IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (T item in source)
|
||||
{
|
||||
if (predicate.Invoke(item))
|
||||
return index;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Repeat<T>(this T item, int times)
|
||||
=> Enumerable.Range(0, times).Select(_ => item);
|
||||
}
|
||||
|
||||
public static IList<TValue> UnionAdd<TValue>(this IList<TValue> source, IEnumerable<TValue> toUnion, IEqualityComparer<TValue> comparer)
|
||||
{
|
||||
foreach (TValue toUnionValue in toUnion)
|
||||
{
|
||||
if (!source.Contains(toUnionValue, comparer))
|
||||
source.Add(toUnionValue);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
public static void UnionAdd<TSource>(this ICollection<TSource> collection, IEnumerable<TSource> target)
|
||||
{
|
||||
foreach (TSource item in target)
|
||||
{
|
||||
if (!collection.Contains(item))
|
||||
collection.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnionAdd<TSource>(this SortedList<TSource, TSource> collection, IEnumerable<TSource> target)
|
||||
{
|
||||
foreach (TSource item in target)
|
||||
{
|
||||
if (!collection.Values.Contains(item))
|
||||
collection.Add(item, item);
|
||||
}
|
||||
}
|
||||
|
||||
public static int IndexOf<T>(this IEnumerable<T> source, Func<T, bool> predicate)
|
||||
{
|
||||
int index = 0;
|
||||
foreach (T item in source)
|
||||
{
|
||||
if (predicate.Invoke(item))
|
||||
return index;
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static IEnumerable<T> Repeat<T>(this T item, int times)
|
||||
=> Enumerable.Range(0, times).Select(_ => item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user