Skip to content

Commit

Permalink
Use nameof where possible (#654)
Browse files Browse the repository at this point in the history
+semver:patch
  • Loading branch information
hazzik authored Mar 11, 2024
1 parent f19aebc commit ae0011f
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 37 deletions.
6 changes: 2 additions & 4 deletions src/FluentNHibernate/AssemblyTypeSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class AssemblyTypeSource : ITypeSource

public AssemblyTypeSource(Assembly source)
{
if (source is null) throw new ArgumentNullException("source");

this.source = source;
this.source = source ?? throw new ArgumentNullException(nameof(source));
}

#region ITypeSource Members
Expand All @@ -29,7 +27,7 @@ public IEnumerable<Type> GetTypes()

public void LogSource(IDiagnosticLogger logger)
{
if (logger is null) throw new ArgumentNullException("logger");
if (logger is null) throw new ArgumentNullException(nameof(logger));

logger.LoadedFluentMappingsFromSource(this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/Cfg/FluentMappingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public FluentMappingsContainer Add<T>()
public FluentMappingsContainer Add(Type type)
{
if (type is null)
throw new ArgumentNullException("type");
throw new ArgumentNullException(nameof(type));

types.Add(type);
WasUsed = true;
Expand Down
15 changes: 2 additions & 13 deletions src/FluentNHibernate/Conventions/ProxyConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,8 @@ public ProxyConvention(
Func<Type, Type> mapPersistentTypeToProxyInterfaceType,
Func<Type, Type> mapProxyInterfaceTypeToPersistentType)
{
if (mapPersistentTypeToProxyInterfaceType is null)
{
throw new ArgumentNullException("mapPersistentTypeToProxyInterfaceType");
}

if(mapProxyInterfaceTypeToPersistentType is null)
{
throw new ArgumentNullException("mapProxyInterfaceTypeToPersistentType");
}

this._mapPersistentTypeToProxyInterfaceType = mapPersistentTypeToProxyInterfaceType;

this._mapProxyInterfaceTypeToPersistentType = mapProxyInterfaceTypeToPersistentType;
_mapPersistentTypeToProxyInterfaceType = mapPersistentTypeToProxyInterfaceType ?? throw new ArgumentNullException(nameof(mapPersistentTypeToProxyInterfaceType));
_mapProxyInterfaceTypeToPersistentType = mapProxyInterfaceTypeToPersistentType ?? throw new ArgumentNullException(nameof(mapProxyInterfaceTypeToPersistentType));
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions src/FluentNHibernate/DummyPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ public sealed class DummyPropertyInfo : PropertyInfo
{
public DummyPropertyInfo(string name, Type type)
{
if (name is null) throw new ArgumentNullException("name");
if (type is null) throw new ArgumentNullException("type");

this.Name = name;
this.DeclaringType = type;
Name = name ?? throw new ArgumentNullException(nameof(name));
DeclaringType = type ?? throw new ArgumentNullException(nameof(type));
}

public override Module Module => null;
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Mapping/FilterDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public FilterDefinition WithCondition(string condition)

public FilterDefinition AddParameter(string name, IType type)
{
if (string.IsNullOrEmpty(name)) throw new ArgumentException("The name is mandatory", "name");
if (type is null) throw new ArgumentNullException("type");
if (string.IsNullOrEmpty(name)) throw new ArgumentException("The name is mandatory", nameof(name));
if (type is null) throw new ArgumentNullException(nameof(type));
parameters.Add(name, type);
return this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/FluentNHibernate/SessionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SessionSource(FluentConfiguration config)

protected void Initialize(Configuration nhibernateConfig, PersistenceModel model)
{
if( model is null ) throw new ArgumentNullException("model", "Model cannot be null");
if (model is null) throw new ArgumentNullException(nameof(model), "Model cannot be null");

Configuration = nhibernateConfig;

Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Testing/Values/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ private void AssertGenericListMatches(IEnumerable actualEnumerable, IEnumerable<
{
if (actualEnumerable is null)
{
throw new ArgumentNullException("actualEnumerable",
throw new ArgumentNullException(nameof(actualEnumerable),
"Actual and expected are not equal (actual was null).");
}
if (expectedEnumerable is null)
{
throw new ArgumentNullException("expectedEnumerable",
throw new ArgumentNullException(nameof(expectedEnumerable),
"Actual and expected are not equal (expected was null).");
}

Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Testing/Values/ReferenceBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ private void AssertGenericListMatches(IEnumerable actualEnumerable, IEnumerable<
{
if (actualEnumerable is null)
{
throw new ArgumentNullException("actualEnumerable",
throw new ArgumentNullException(nameof(actualEnumerable),
"Actual and expected are not equal (actual was null).");
}
if (expectedEnumerable is null)
{
throw new ArgumentNullException("expectedEnumerable",
throw new ArgumentNullException(nameof(expectedEnumerable),
"Actual and expected are not equal (expected was null).");
}

Expand Down
6 changes: 3 additions & 3 deletions src/FluentNHibernate/Utils/ObservableDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public bool ContainsKey(TKey key) {
public ICollection<TKey> Keys => Dictionary.Keys;

public bool Remove(TKey key) {
if (key is null) throw new ArgumentNullException("key");
if (key is null) throw new ArgumentNullException(nameof(key));

TValue value;
Dictionary.TryGetValue(key, out value);
Expand Down Expand Up @@ -140,7 +140,7 @@ IEnumerator IEnumerable.GetEnumerator() {
#endregion

public void AddRange(IDictionary<TKey, TValue> items) {
if (items is null) throw new ArgumentNullException("items");
if (items is null) throw new ArgumentNullException(nameof(items));

if (items.Count > 0) {
if (Dictionary.Count > 0) {
Expand All @@ -156,7 +156,7 @@ public void AddRange(IDictionary<TKey, TValue> items) {
}

private void Insert(TKey key, TValue value, bool add) {
if (key is null) throw new ArgumentNullException("key");
if (key is null) throw new ArgumentNullException(nameof(key));

TValue item;
if (Dictionary.TryGetValue(key, out item)) {
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Utils/Reflection/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static PropertyInfo GetDynamicComponentProperty(Expression expression)
}

if (nextOperand.NodeType != ExpressionType.Convert)
throw new ArgumentException("Expression not supported", "expression");
throw new ArgumentException("Expression not supported", nameof(expression));

var unaryExpression = (UnaryExpression)nextOperand;
desiredConversionType = unaryExpression.Type;
Expand Down Expand Up @@ -107,7 +107,7 @@ private static MemberExpression GetMemberExpression(Expression expression, bool

if (enforceCheck && memberExpression is null)
{
throw new ArgumentException("Not a member access", "expression");
throw new ArgumentException("Not a member access", nameof(expression));
}

return memberExpression;
Expand Down
4 changes: 2 additions & 2 deletions src/FluentNHibernate/Utils/StringLikeness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public static class StringLikeness
public static int EditDistance(string x, string y)
{
// Validate parameters
if (x is null) throw new ArgumentNullException("x");
if (y is null) throw new ArgumentNullException("y");
if (x is null) throw new ArgumentNullException(nameof(x));
if (y is null) throw new ArgumentNullException(nameof(y));

// Convert the parameters into IList instances
// in order to obtain indexing capabilities
Expand Down

0 comments on commit ae0011f

Please sign in to comment.