Split Geekbot.net into src/Bot, src/Core, and src/Web
This commit is contained in:
parent
7b6dd2d2f9
commit
fc0af492ad
197 changed files with 542 additions and 498 deletions
28
src/Core/Extensions/DbSetExtensions.cs
Normal file
28
src/Core/Extensions/DbSetExtensions.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class DbSetExtensions
|
||||
{
|
||||
public static EntityEntry<T> AddIfNotExists<T>(this DbSet<T> dbSet, T entity, Expression<Func<T, bool>> predicate = null) where T : class, new()
|
||||
{
|
||||
var exists = predicate != null ? dbSet.Any(predicate) : dbSet.Any();
|
||||
return !exists ? dbSet.Add(entity) : null;
|
||||
}
|
||||
|
||||
// https://github.com/dotnet/efcore/issues/18124
|
||||
public static IAsyncEnumerable<TEntity> AsAsyncEnumerable<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj) where TEntity : class
|
||||
{
|
||||
return Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.AsAsyncEnumerable(obj);
|
||||
}
|
||||
public static IQueryable<TEntity> Where<TEntity>(this Microsoft.EntityFrameworkCore.DbSet<TEntity> obj, System.Linq.Expressions.Expression<Func<TEntity, bool>> predicate) where TEntity : class
|
||||
{
|
||||
return System.Linq.Queryable.Where(obj, predicate);
|
||||
}
|
||||
}
|
||||
}
|
12
src/Core/Extensions/EmbedBuilderExtensions.cs
Normal file
12
src/Core/Extensions/EmbedBuilderExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using Discord;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class EmbedBuilderExtensions
|
||||
{
|
||||
public static EmbedBuilder AddInlineField(this EmbedBuilder builder, string name, object value)
|
||||
{
|
||||
return builder.AddField(new EmbedFieldBuilder().WithIsInline(true).WithName(name).WithValue(value));
|
||||
}
|
||||
}
|
||||
}
|
15
src/Core/Extensions/IntExtensions.cs
Normal file
15
src/Core/Extensions/IntExtensions.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class IntExtensions
|
||||
{
|
||||
public static void Times(this int count, Action action)
|
||||
{
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
action();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
src/Core/Extensions/LongExtensions.cs
Normal file
12
src/Core/Extensions/LongExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class LongExtensions
|
||||
{
|
||||
public static ulong AsUlong(this long thing)
|
||||
{
|
||||
return Convert.ToUInt64(thing);
|
||||
}
|
||||
}
|
||||
}
|
12
src/Core/Extensions/StringExtensions.cs
Normal file
12
src/Core/Extensions/StringExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Linq;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static string CapitalizeFirst(this string source)
|
||||
{
|
||||
return source.First().ToString().ToUpper() + source.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
12
src/Core/Extensions/UlongExtensions.cs
Normal file
12
src/Core/Extensions/UlongExtensions.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.Core.Extensions
|
||||
{
|
||||
public static class UlongExtensions
|
||||
{
|
||||
public static long AsLong(this ulong thing)
|
||||
{
|
||||
return Convert.ToInt64(thing);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue