Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Identity(UserCreated @event)

public void Apply(IdentityAdded @event)
{
if (@event is null) throw new ArgumentNullException();
ArgumentNullException.ThrowIfNull(@event);

LastName = @event.LastName;
FirstName = @event.FirstName;
Expand Down
3 changes: 1 addition & 2 deletions src/Marten.Testing/Harness/SpecificationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public static void ShouldBeEqualWithDbPrecision(this DateTimeOffset actual, Date

public static void ShouldContain(this DbObjectName[] names, string qualifiedName)
{
if (names == null)
throw new ArgumentNullException(nameof(names));
ArgumentNullException.ThrowIfNull(names);

var function = DbObjectName.Parse(PostgresqlProvider.Instance, qualifiedName);
names.ShouldContain(function);
Expand Down
5 changes: 1 addition & 4 deletions src/Marten/Events/EventGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ public string AggregateAliasFor(Type aggregateType)

public IEvent BuildEvent(object eventData)
{
if (eventData == null)
{
throw new ArgumentNullException(nameof(eventData));
}
ArgumentNullException.ThrowIfNull(eventData);

var mapping = EventMappingFor(eventData.GetType());
return mapping.Wrap(eventData);
Expand Down
15 changes: 3 additions & 12 deletions src/Marten/Internal/Sessions/DocumentSessionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public void Store<T>(IEnumerable<T> entities) where T : notnull

public void Store<T>(params T[] entities) where T : notnull
{
if (entities == null)
{
throw new ArgumentNullException(nameof(entities));
}
ArgumentNullException.ThrowIfNull(entities);

if (typeof(T).IsGenericEnumerable())
{
Expand Down Expand Up @@ -124,10 +121,7 @@ public void Insert<T>(params T[] entities) where T : notnull
{
assertNotDisposed();

if (entities == null)
{
throw new ArgumentNullException(nameof(entities));
}
ArgumentNullException.ThrowIfNull(entities);

if (typeof(T).IsGenericEnumerable())
{
Expand Down Expand Up @@ -162,10 +156,7 @@ public void Update<T>(params T[] entities) where T : notnull
{
assertNotDisposed();

if (entities == null)
{
throw new ArgumentNullException(nameof(entities));
}
ArgumentNullException.ThrowIfNull(entities);

if (typeof(T).IsGenericEnumerable())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ internal class EventTracingConnectionLifetime:
public EventTracingConnectionLifetime(IConnectionLifetime innerConnectionLifetime, string tenantId,
OpenTelemetryOptions telemetryOptions)
{
if (innerConnectionLifetime == null)
{
throw new ArgumentNullException(nameof(innerConnectionLifetime));
}
ArgumentNullException.ThrowIfNull(innerConnectionLifetime);

if (string.IsNullOrWhiteSpace(tenantId))
{
Expand Down
10 changes: 2 additions & 8 deletions src/Marten/JsonLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public JsonLoader(QuerySession session)

public Task<string?> FindByIdAsync<T>(object id, CancellationToken token = default) where T : class
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
ArgumentNullException.ThrowIfNull(id);

var streamer = typeof(Streamer<,>).CloseAndBuildAs<IStreamer<T>>(this, typeof(T), id.GetType());
return streamer.FindByIdAsync(id, token);
Expand Down Expand Up @@ -51,10 +48,7 @@ public JsonLoader(QuerySession session)

public Task<bool> StreamById<T>(object id, Stream destination, CancellationToken token = default) where T : class
{
if (id == null)
{
throw new ArgumentNullException(nameof(id));
}
ArgumentNullException.ThrowIfNull(id);

var streamer = typeof(Streamer<,>).CloseAndBuildAs<IStreamer<T>>(this, typeof(T), id.GetType());
return streamer.StreamJsonById(id, destination, token);
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Linq/Members/QueryableMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class QueryableMember: IQueryableMember, IHasChildrenMembers
/// <param name="member"></param>
protected QueryableMember(IQueryableMember parent, Casing casing, MemberInfo member)
{
if (parent == null) throw new ArgumentNullException(nameof(parent));
ArgumentNullException.ThrowIfNull(parent);

Member = member;
MemberType = member is ElementMember m ? m.ReflectedType : member.GetMemberType()!;
Expand Down
5 changes: 1 addition & 4 deletions src/Marten/Linq/SqlGeneration/FilterStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ internal class FilterStatement: SelectorStatement
{
public FilterStatement(IMartenSession session, Statement parent, ISqlFragment where)
{
if (where == null)
{
throw new ArgumentNullException(nameof(where));
}
ArgumentNullException.ThrowIfNull(where);

Wheres.Add(where);

Expand Down
125 changes: 25 additions & 100 deletions src/Marten/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ public static Task<bool> AnyAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().AnyAsync(token);
}
Expand All @@ -316,15 +313,9 @@ public static Task<bool> AnyAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).AnyAsync(token);
}
Expand All @@ -337,10 +328,7 @@ public static Task<TResult> SumAsync<TSource, TResult>(
this IQueryable<TSource> source, Expression<Func<TSource, TResult>> expression,
CancellationToken token = default) where TResult : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.Select(expression).As<MartenLinqQueryable<TResult>>().SumAsync<TResult>(token);
}
Expand All @@ -349,10 +337,7 @@ public static Task<TResult> MaxAsync<TSource, TResult>(
this IQueryable<TSource> source, Expression<Func<TSource, TResult>> expression,
CancellationToken token = default) where TResult : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.Select(expression).As<MartenLinqQueryable<TResult>>().MaxAsync<TResult>(token);
}
Expand All @@ -361,10 +346,7 @@ public static Task<TResult> MinAsync<TSource, TResult>(
this IQueryable<TSource> source, Expression<Func<TSource, TResult>> expression,
CancellationToken token = default) where TResult : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.Select(expression).As<MartenLinqQueryable<TResult>>().MinAsync<TResult>(token);
}
Expand All @@ -373,10 +355,7 @@ public static Task<double> AverageAsync<TSource, TMember>(
this IQueryable<TSource> source, Expression<Func<TSource, TMember>> expression,
CancellationToken token = default) where TMember : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.Select(expression).As<MartenLinqQueryable<TMember>>().AverageAsync(token);
}
Expand All @@ -389,10 +368,7 @@ public static Task<int> CountAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().CountAsync(token);
}
Expand All @@ -402,15 +378,9 @@ public static Task<int> CountAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).CountAsync(token);
}
Expand All @@ -419,10 +389,7 @@ public static Task<long> LongCountAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().CountLongAsync(token);
}
Expand All @@ -432,15 +399,9 @@ public static Task<long> LongCountAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).LongCountAsync(token);
}
Expand All @@ -453,10 +414,7 @@ public static Task<TSource> FirstAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().FirstAsync<TSource>(token);
}
Expand All @@ -466,15 +424,9 @@ public static Task<TSource> FirstAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).FirstAsync(token);
}
Expand All @@ -483,10 +435,7 @@ public static Task<TSource> FirstAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().FirstOrDefaultAsync<TSource>(token);
}
Expand All @@ -496,15 +445,9 @@ public static Task<TSource> FirstAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).FirstOrDefaultAsync(token);
}
Expand All @@ -517,10 +460,7 @@ public static Task<TSource> SingleAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().SingleAsync<TSource>(token);
}
Expand All @@ -530,15 +470,9 @@ public static Task<TSource> SingleAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).SingleAsync(token);
}
Expand All @@ -547,10 +481,7 @@ public static Task<TSource> SingleAsync<TSource>(
this IQueryable<TSource> source,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

return source.As<MartenLinqQueryable<TSource>>().SingleOrDefaultAsync<TSource>(token);
}
Expand All @@ -560,15 +491,9 @@ public static Task<TSource> SingleAsync<TSource>(
Expression<Func<TSource, bool>> predicate,
CancellationToken token = default) where TSource : notnull
{
if (source == null)
{
throw new ArgumentNullException(nameof(source));
}
ArgumentNullException.ThrowIfNull(source);

if (predicate == null)
{
throw new ArgumentNullException(nameof(predicate));
}
ArgumentNullException.ThrowIfNull(predicate);

return source.Where(predicate).SingleOrDefaultAsync(token);
}
Expand Down
5 changes: 1 addition & 4 deletions src/Marten/Schema/Arguments/UpsertArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ public string PostgresType
get => _postgresType;
set
{
if (value == null)
{
throw new ArgumentNullException();
}
ArgumentNullException.ThrowIfNull(value);

_postgresType = value.Contains("(")
? value.Split('(')[0].Trim()
Expand Down
Loading