Skip to content

Commit b923566

Browse files
authored
Refactor to ArgumentException.ThrowIfNullOrEmpty() usage (#269)
1 parent 4f784dd commit b923566

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+130
-168
lines changed

Orm/Xtensive.Orm.Tests.Framework/Measurement.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string Name
3434
get { return name; }
3535
[DebuggerStepThrough]
3636
set {
37-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
37+
ArgumentException.ThrowIfNullOrEmpty(value);
3838
name = value;
3939
UpdateFullName();
4040
}
@@ -231,4 +231,4 @@ void IDisposable.Dispose()
231231
Complete();
232232
}
233233
}
234-
}
234+
}

Orm/Xtensive.Orm.Tests.Framework/TestSqlDriver.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ public static SqlDriver Create(UrlInfo connectionUrl)
2424

2525
public static SqlDriver Create(string connectionUrl)
2626
{
27-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionUrl, "connectionUrl");
27+
ArgumentException.ThrowIfNullOrEmpty(connectionUrl);
2828
return BuildDriver(new ConnectionInfo(connectionUrl));
2929
}
3030

3131
public static SqlDriver Create(string provider, string connectionString)
3232
{
33-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(provider, "provider");
34-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionString, "connectionString");
33+
ArgumentException.ThrowIfNullOrEmpty(provider);
34+
ArgumentException.ThrowIfNullOrEmpty(connectionString);
3535
return BuildDriver(new ConnectionInfo(provider, connectionString));
3636
}
3737

@@ -59,4 +59,4 @@ private static SqlDriverFactory GetFactory(string provider)
5959
}
6060
}
6161
}
62-
}
62+
}

Orm/Xtensive.Orm/Collections/TypeRegistry.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void Register(Assembly assembly, string @namespace)
9696
{
9797
EnsureNotLocked();
9898
ArgumentNullException.ThrowIfNull(assembly);
99-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(@namespace, "@namespace");
99+
ArgumentException.ThrowIfNullOrEmpty(@namespace);
100100
Register(new TypeRegistration(assembly, @namespace));
101101
}
102102

Orm/Xtensive.Orm/Core/ArgumentValidator.cs

-37
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,6 @@ public static void EnsureArgumentIsNotDefault<T>(T value, [InvokerParameterName]
3737
}
3838
}
3939

40-
/// <summary>
41-
/// Ensures argument (<paramref name="value"/>) is not
42-
/// <see langoword="null"/> or <see cref="string.Empty"/> string.
43-
/// </summary>
44-
/// <param name="value">Value to check.</param>
45-
/// <param name="parameterName">Name of the method parameter.</param>
46-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
47-
#if NET7_0_OR_GREATER
48-
[Obsolete("Use ArgumentException.ThrowIfNullOrEmpty()")]
49-
#endif
50-
internal static void EnsureArgumentNotNullOrEmpty(string value, [InvokerParameterName] string parameterName)
51-
{
52-
#if NET7_0_OR_GREATER
53-
ArgumentException.ThrowIfNullOrEmpty(value, parameterName);
54-
#else
55-
ArgumentNullException.ThrowIfNull(value, parameterName);
56-
if (value.Length == 0) {
57-
throw new ArgumentException(Strings.ExArgumentCannotBeEmptyString, parameterName);
58-
}
59-
#endif
60-
}
61-
62-
[Obsolete("Use CommunityToolkit.Diagnostics.Guard.IsNotNullOrWhiteSpace()")]
63-
[MethodImpl(MethodImplOptions.AggressiveInlining)]
64-
internal static void EnsureArgumentNotNullOrEmptyOrWhiteSpace(string value, [InvokerParameterName] string parameterName)
65-
{
66-
ArgumentNullException.ThrowIfNull(value, parameterName);
67-
68-
if (value.Length==0) {
69-
throw new ArgumentException(Strings.ExArgumentCannotBeEmptyString, parameterName);
70-
}
71-
72-
if (value.Trim().Length==0) {
73-
throw new ArgumentException(Strings.ExArgumentCannotBeWhiteSpacesOnlyString, parameterName);
74-
}
75-
}
76-
7740
/// <summary>
7841
/// Ensures argument (<paramref name="value"/>) is not <see langword="null"/>
7942
/// and of <typeparamref name="T"/> type.

Orm/Xtensive.Orm/Linq/SerializableExpressions/Internals/ReflectionExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static ConstructorInfo GetConstructorFromSerializableForm(this string ser
8787

8888
public static void AddArray<T>(this SerializationInfo info, string key, T[] array)
8989
{
90-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(key, "key");
90+
ArgumentException.ThrowIfNullOrEmpty(key);
9191
ArgumentNullException.ThrowIfNull(array);
9292

9393
info.AddValue($"{key}Count", array.Length);
@@ -97,7 +97,7 @@ public static void AddArray<T>(this SerializationInfo info, string key, T[] arra
9797

9898
public static T[] GetArrayFromSerializableForm<T>(this SerializationInfo info, string key)
9999
{
100-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(key, "key");
100+
ArgumentException.ThrowIfNullOrEmpty(key);
101101

102102
var count = info.GetInt32($"{key}Count");
103103
var array = new T[count];

Orm/Xtensive.Orm/Modelling/Actions/CreateNodeAction.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Type Type {
4343
public string Name {
4444
get { return name; }
4545
set {
46-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
46+
ArgumentException.ThrowIfNullOrEmpty(value);
4747
EnsureNotLocked();
4848
name = value;
4949
}
@@ -122,4 +122,4 @@ protected override void GetParameters(List<Pair<string>> parameters)
122122
parameters.Add(new Pair<string>("Parameters", this.parameters.ToCommaDelimitedString()));
123123
}
124124
}
125-
}
125+
}

Orm/Xtensive.Orm/Modelling/Comparison/Hints/DataHint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ public override List<HintTarget> GetTargets()
4949
/// </summary>
5050
protected DataHint(string sourceTablePath, IReadOnlyList<IdentityPair> identities)
5151
{
52-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceTablePath, "sourceTablePath");
52+
ArgumentException.ThrowIfNullOrEmpty(sourceTablePath);
5353
ArgumentNullException.ThrowIfNull(identities, "pairs");
5454

5555
SourceTablePath = sourceTablePath;
5656
Identities = identities.AsSafeWrapper();
5757
}
5858
}
59-
}
59+
}

Orm/Xtensive.Orm/Modelling/Comparison/Hints/IgnoreHint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ public override string ToString()
4444
/// <param name="path">The ignored node path.</param>
4545
public IgnoreHint(string path)
4646
{
47-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(path, "path");
47+
ArgumentException.ThrowIfNullOrEmpty(path);
4848
Path = path;
4949
}
5050
}
51-
}
51+
}

Orm/Xtensive.Orm/Modelling/Nesting.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ internal virtual void Initialize()
7373
internal Nesting(Node node, string propertyName)
7474
{
7575
ArgumentNullException.ThrowIfNull(node);
76-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(propertyName, "propertyName");
76+
ArgumentException.ThrowIfNullOrEmpty(propertyName);
7777
Node = node;
7878
PropertyName = propertyName;
7979
Initialize();
@@ -86,4 +86,4 @@ internal Nesting(Node node)
8686
Initialize();
8787
}
8888
}
89-
}
89+
}

Orm/Xtensive.Orm/Modelling/Node.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ protected virtual void CopyPropertyValue(Node target, PropertyAccessor accessor)
428428
/// <exception cref="InvalidOperationException">newName!=newIndex for <see cref="IUnnamedNode"/>.</exception>
429429
protected virtual void ValidateMove(Node newParent, string newName, int newIndex)
430430
{
431-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(newName, nameof(newName));
431+
ArgumentException.ThrowIfNullOrEmpty(newName);
432432
if (this is IModel) {
433433
ArgumentValidator.EnsureArgumentIsInRange(newIndex, 0, 0, nameof(newIndex));
434434
return;
@@ -1012,7 +1012,7 @@ protected Node(Node parent, string name)
10121012
}
10131013

10141014
if (!(this is IUnnamedNode)) {
1015-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, nameof(name));
1015+
ArgumentException.ThrowIfNullOrEmpty(name);
10161016
}
10171017

10181018
Initialize();
@@ -1044,4 +1044,4 @@ void IDeserializationCallback.OnDeserialization(object sender)
10441044
}
10451045
}
10461046
}
1047-
}
1047+
}

Orm/Xtensive.Orm/Modelling/NodeCollection.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ protected virtual void Initialize()
372372
protected NodeCollection(Node parent, string name)
373373
{
374374
ArgumentNullException.ThrowIfNull(parent);
375-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
375+
ArgumentException.ThrowIfNullOrEmpty(name);
376376
this.name = name;
377377
this.parent = parent;
378378
Initialize();
@@ -394,4 +394,3 @@ void IDeserializationCallback.OnDeserialization(object sender)
394394
}
395395
}
396396
}
397-

Orm/Xtensive.Orm/Orm/Building/Definitions/TypeDef.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public FieldDef DefineField(PropertyInfo property)
171171
/// <returns></returns>
172172
public FieldDef DefineField(string name, Type valueType)
173173
{
174-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, nameof(name));
174+
ArgumentException.ThrowIfNullOrEmpty(name);
175175
ArgumentNullException.ThrowIfNull(valueType);
176176

177177
var field = builder.DefineField(UnderlyingType, name, valueType);
@@ -221,4 +221,4 @@ internal TypeDef(ModelDefBuilder builder, Type type, Validator validator)
221221
: NodeCollection<TypeDef>.Empty;
222222
}
223223
}
224-
}
224+
}

Orm/Xtensive.Orm/Orm/Configuration/DatabaseConfiguration.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public string Name
2828
get { return name; }
2929
set
3030
{
31-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
31+
ArgumentException.ThrowIfNullOrEmpty(value);
3232
EnsureNotLocked();
3333
name = value;
3434
}
@@ -109,10 +109,10 @@ public DatabaseConfiguration Clone()
109109
/// <param name="name">Database name.</param>
110110
public DatabaseConfiguration(string name)
111111
{
112-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
112+
ArgumentException.ThrowIfNullOrEmpty(name);
113113
Name = name;
114114
minTypeId = TypeInfo.MinTypeId;
115115
maxTypeId = int.MaxValue;
116116
}
117117
}
118-
}
118+
}

Orm/Xtensive.Orm/Orm/Configuration/DomainConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static string SectionName
170170
{
171171
get => sectionName;
172172
set {
173-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
173+
ArgumentException.ThrowIfNullOrEmpty(value);
174174
if (sectionNameIsDefined) {
175175
throw Exceptions.AlreadyInitialized(nameof(SectionName));
176176
}

Orm/Xtensive.Orm/Orm/Configuration/KeyGeneratorConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public string Name
2626
get { return name; }
2727
set
2828
{
29-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(value, "value");
29+
ArgumentException.ThrowIfNullOrEmpty(value);
3030
EnsureNotLocked();
3131
name = value;
3232
}
@@ -96,4 +96,4 @@ public KeyGeneratorConfiguration(string name)
9696
CacheSize = DomainConfiguration.DefaultKeyGeneratorCacheSize;
9797
}
9898
}
99-
}
99+
}

Orm/Xtensive.Orm/Orm/Configuration/LoggingConfiguration.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static LoggingConfiguration Load()
4343
/// <returns>Loaded configuration.</returns>
4444
public static LoggingConfiguration Load(string sectionName)
4545
{
46-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sectionName, "sectionName");
46+
ArgumentException.ThrowIfNullOrEmpty(sectionName);
4747

4848
var section = (ConfigurationSection)ConfigurationManager.GetSection(sectionName);
4949
if (section==null)
@@ -71,7 +71,7 @@ public static LoggingConfiguration Load(System.Configuration.Configuration confi
7171
public static LoggingConfiguration Load(System.Configuration.Configuration configuration, string sectionName)
7272
{
7373
ArgumentNullException.ThrowIfNull(configuration);
74-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sectionName, "sectionName");
74+
ArgumentException.ThrowIfNullOrEmpty(sectionName);
7575

7676
var section = (ConfigurationSection) configuration.GetSection(sectionName);
7777
if (section==null)

Orm/Xtensive.Orm/Orm/Configuration/NameMappingCollection.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public class NameMappingCollection : LockableBase, IEnumerable<KeyValuePair<stri
3838
/// <param name="mappedName"></param>
3939
public void Add([NotNull] string originalName, [NotNull] string mappedName)
4040
{
41-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(originalName, "originalName");
42-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(mappedName, "mappedName");
41+
ArgumentException.ThrowIfNullOrEmpty(originalName);
42+
ArgumentException.ThrowIfNullOrEmpty(mappedName);
4343
EnsureNotLocked();
4444
items[originalName] = mappedName;
4545
}
@@ -50,7 +50,7 @@ public void Add([NotNull] string originalName, [NotNull] string mappedName)
5050
/// <param name="originalName"></param>
5151
public bool Remove([NotNull] string originalName)
5252
{
53-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(originalName, "originalName");
53+
ArgumentException.ThrowIfNullOrEmpty(originalName);
5454
EnsureNotLocked();
5555
return items.Remove(originalName);
5656
}
@@ -61,7 +61,7 @@ public bool Remove([NotNull] string originalName)
6161
/// <param name="name">Mapped name for <paramref name="name"/>.</param>
6262
public string Apply([NotNull] string name)
6363
{
64-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
64+
ArgumentException.ThrowIfNullOrEmpty(name);
6565
string result;
6666
if (items.TryGetValue(name, out result))
6767
return result;
@@ -126,4 +126,4 @@ static NameMappingCollection()
126126
Empty.Lock();
127127
}
128128
}
129-
}
129+
}

Orm/Xtensive.Orm/Orm/Configuration/SessionConfiguration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public SessionConfiguration(string name)
305305
/// <param name="name">Value for <see cref="Name"/>.</param>
306306
public SessionConfiguration(string name, SessionOptions sessionOptions)
307307
{
308-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(name, "name");
308+
ArgumentException.ThrowIfNullOrEmpty(name);
309309

310310
Name = name;
311311
Options = sessionOptions;

Orm/Xtensive.Orm/Orm/Configuration/SessionConfigurationCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public override void AddRange(IEnumerable<SessionConfiguration> items)
9191

9292
private void EnsureItemIsValid(SessionConfiguration item)
9393
{
94-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(item.Name, "SessionConfiguration.Name");
94+
ArgumentException.ThrowIfNullOrEmpty(item.Name, "SessionConfiguration.Name");
9595
var current = this[item.Name];
9696
if (current != null)
9797
throw new InvalidOperationException(string.Format(Strings.ExConfigurationWithXNameAlreadyRegistered, current.Name));

Orm/Xtensive.Orm/Orm/ConnectionInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ public bool Equals(ConnectionInfo other)
9393
/// <param name="connectionString">A value for <see cref="ConnectionString"/>.</param>
9494
public ConnectionInfo(string provider, string connectionString)
9595
{
96-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(provider, "provider");
97-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(connectionString, "connectionString");
96+
ArgumentException.ThrowIfNullOrEmpty(provider);
97+
ArgumentException.ThrowIfNullOrEmpty(connectionString);
9898

9999
ConnectionString = connectionString;
100100
Provider = provider.ToLowerInvariant();

Orm/Xtensive.Orm/Orm/ConnectionInitEventData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ConnectionInitEventData : ConnectionEventData
2020
public ConnectionInitEventData(string initializationScript, DbConnection connection, bool reconnect = false)
2121
: base(connection, reconnect)
2222
{
23-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(initializationScript, nameof(initializationScript));
23+
ArgumentException.ThrowIfNullOrEmpty(initializationScript);
2424
InitializationScript = initializationScript;
2525
}
2626
}

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Nodes/PrefixTerm.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ internal PrefixTerm(string prefix)
3030
internal PrefixTerm(IOperator source, string prefix)
3131
: base(SearchConditionNodeType.Prefix, source)
3232
{
33-
ArgumentValidator.EnsureArgumentNotNullOrEmptyOrWhiteSpace(prefix, "prefix");
33+
ArgumentException.ThrowIfNullOrWhiteSpace(prefix);
3434
Prefix = prefix;
3535
}
3636
}
37-
}
37+
}

Orm/Xtensive.Orm/Orm/FullTextSearchCondition/Nodes/SimpleTerm.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal SimpleTerm(string term)
3030
internal SimpleTerm(IOperator source, string term)
3131
: base(SearchConditionNodeType.SimpleTerm, source)
3232
{
33-
ArgumentValidator.EnsureArgumentNotNullOrEmptyOrWhiteSpace(term, "term");
33+
ArgumentException.ThrowIfNullOrWhiteSpace(term);
3434
Term = term;
3535
}
3636
}

0 commit comments

Comments
 (0)