Skip to content

Commit ae0011f

Browse files
authored
Use nameof where possible (#654)
+semver:patch
1 parent f19aebc commit ae0011f

File tree

11 files changed

+21
-37
lines changed

11 files changed

+21
-37
lines changed

src/FluentNHibernate/AssemblyTypeSource.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ public class AssemblyTypeSource : ITypeSource
1515

1616
public AssemblyTypeSource(Assembly source)
1717
{
18-
if (source is null) throw new ArgumentNullException("source");
19-
20-
this.source = source;
18+
this.source = source ?? throw new ArgumentNullException(nameof(source));
2119
}
2220

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

3028
public void LogSource(IDiagnosticLogger logger)
3129
{
32-
if (logger is null) throw new ArgumentNullException("logger");
30+
if (logger is null) throw new ArgumentNullException(nameof(logger));
3331

3432
logger.LoadedFluentMappingsFromSource(this);
3533
}

src/FluentNHibernate/Cfg/FluentMappingsContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public FluentMappingsContainer Add<T>()
6767
public FluentMappingsContainer Add(Type type)
6868
{
6969
if (type is null)
70-
throw new ArgumentNullException("type");
70+
throw new ArgumentNullException(nameof(type));
7171

7272
types.Add(type);
7373
WasUsed = true;

src/FluentNHibernate/Conventions/ProxyConvention.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,8 @@ public ProxyConvention(
1313
Func<Type, Type> mapPersistentTypeToProxyInterfaceType,
1414
Func<Type, Type> mapProxyInterfaceTypeToPersistentType)
1515
{
16-
if (mapPersistentTypeToProxyInterfaceType is null)
17-
{
18-
throw new ArgumentNullException("mapPersistentTypeToProxyInterfaceType");
19-
}
20-
21-
if(mapProxyInterfaceTypeToPersistentType is null)
22-
{
23-
throw new ArgumentNullException("mapProxyInterfaceTypeToPersistentType");
24-
}
25-
26-
this._mapPersistentTypeToProxyInterfaceType = mapPersistentTypeToProxyInterfaceType;
27-
28-
this._mapProxyInterfaceTypeToPersistentType = mapProxyInterfaceTypeToPersistentType;
16+
_mapPersistentTypeToProxyInterfaceType = mapPersistentTypeToProxyInterfaceType ?? throw new ArgumentNullException(nameof(mapPersistentTypeToProxyInterfaceType));
17+
_mapProxyInterfaceTypeToPersistentType = mapProxyInterfaceTypeToPersistentType ?? throw new ArgumentNullException(nameof(mapProxyInterfaceTypeToPersistentType));
2918
}
3019

3120
/// <summary>

src/FluentNHibernate/DummyPropertyInfo.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@ public sealed class DummyPropertyInfo : PropertyInfo
99
{
1010
public DummyPropertyInfo(string name, Type type)
1111
{
12-
if (name is null) throw new ArgumentNullException("name");
13-
if (type is null) throw new ArgumentNullException("type");
14-
15-
this.Name = name;
16-
this.DeclaringType = type;
12+
Name = name ?? throw new ArgumentNullException(nameof(name));
13+
DeclaringType = type ?? throw new ArgumentNullException(nameof(type));
1714
}
1815

1916
public override Module Module => null;

src/FluentNHibernate/Mapping/FilterDefinition.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public FilterDefinition WithCondition(string condition)
3333

3434
public FilterDefinition AddParameter(string name, IType type)
3535
{
36-
if (string.IsNullOrEmpty(name)) throw new ArgumentException("The name is mandatory", "name");
37-
if (type is null) throw new ArgumentNullException("type");
36+
if (string.IsNullOrEmpty(name)) throw new ArgumentException("The name is mandatory", nameof(name));
37+
if (type is null) throw new ArgumentNullException(nameof(type));
3838
parameters.Add(name, type);
3939
return this;
4040
}

src/FluentNHibernate/SessionSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public SessionSource(FluentConfiguration config)
4343

4444
protected void Initialize(Configuration nhibernateConfig, PersistenceModel model)
4545
{
46-
if( model is null ) throw new ArgumentNullException("model", "Model cannot be null");
46+
if (model is null) throw new ArgumentNullException(nameof(model), "Model cannot be null");
4747

4848
Configuration = nhibernateConfig;
4949

src/FluentNHibernate/Testing/Values/List.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ private void AssertGenericListMatches(IEnumerable actualEnumerable, IEnumerable<
6565
{
6666
if (actualEnumerable is null)
6767
{
68-
throw new ArgumentNullException("actualEnumerable",
68+
throw new ArgumentNullException(nameof(actualEnumerable),
6969
"Actual and expected are not equal (actual was null).");
7070
}
7171
if (expectedEnumerable is null)
7272
{
73-
throw new ArgumentNullException("expectedEnumerable",
73+
throw new ArgumentNullException(nameof(expectedEnumerable),
7474
"Actual and expected are not equal (expected was null).");
7575
}
7676

src/FluentNHibernate/Testing/Values/ReferenceBag.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ private void AssertGenericListMatches(IEnumerable actualEnumerable, IEnumerable<
2121
{
2222
if (actualEnumerable is null)
2323
{
24-
throw new ArgumentNullException("actualEnumerable",
24+
throw new ArgumentNullException(nameof(actualEnumerable),
2525
"Actual and expected are not equal (actual was null).");
2626
}
2727
if (expectedEnumerable is null)
2828
{
29-
throw new ArgumentNullException("expectedEnumerable",
29+
throw new ArgumentNullException(nameof(expectedEnumerable),
3030
"Actual and expected are not equal (expected was null).");
3131
}
3232

src/FluentNHibernate/Utils/ObservableDictionary.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public bool ContainsKey(TKey key) {
5656
public ICollection<TKey> Keys => Dictionary.Keys;
5757

5858
public bool Remove(TKey key) {
59-
if (key is null) throw new ArgumentNullException("key");
59+
if (key is null) throw new ArgumentNullException(nameof(key));
6060

6161
TValue value;
6262
Dictionary.TryGetValue(key, out value);
@@ -140,7 +140,7 @@ IEnumerator IEnumerable.GetEnumerator() {
140140
#endregion
141141

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

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

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

161161
TValue item;
162162
if (Dictionary.TryGetValue(key, out item)) {

src/FluentNHibernate/Utils/Reflection/ReflectionHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static PropertyInfo GetDynamicComponentProperty(Expression expression)
7575
}
7676

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

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

108108
if (enforceCheck && memberExpression is null)
109109
{
110-
throw new ArgumentException("Not a member access", "expression");
110+
throw new ArgumentException("Not a member access", nameof(expression));
111111
}
112112

113113
return memberExpression;

0 commit comments

Comments
 (0)