Skip to content

Commit

Permalink
Use nameof operator in argument validation
Browse files Browse the repository at this point in the history
  • Loading branch information
stakx committed Jan 4, 2021
1 parent 620de74 commit f2a75e0
Show file tree
Hide file tree
Showing 65 changed files with 141 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public RemoveIfAttribute(params object[] values) : this()

public RemoveIfAttribute(object[] values, Type comparerType) : this()
{
var comparer = Construct<IEqualityComparer>(comparerType, "comparerType");
var comparer = Construct<IEqualityComparer>(comparerType, nameof(comparerType));
condition = new ValueCondition(values, comparer);
}

Expand All @@ -51,7 +51,7 @@ protected RemoveIfAttribute(ICondition condition) : this()

public Type Condition
{
set { condition = Construct<ICondition>(value, "value"); }
set { condition = Construct<ICondition>(value, nameof(value)); }
}

bool IDictionaryPropertySetter.SetPropertyValue(IDictionaryAdapter dictionaryAdapter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public StringFormatAttribute(string format, string properties)
{
if (format == null)
{
throw new ArgumentNullException("format");
throw new ArgumentNullException(nameof(format));
}

Format = format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class XPathAttribute : Attribute
public XPathAttribute(string path)
{
if (path == null)
throw Error.ArgumentNull("path");
throw Error.ArgumentNull(nameof(path));

this.getPath = XPathCompiler.Compile(path);
this.setPath = this.getPath;
Expand All @@ -34,9 +34,9 @@ public XPathAttribute(string path)
public XPathAttribute(string get, string set)
{
if (get == null)
throw Error.ArgumentNull("get");
throw Error.ArgumentNull(nameof(get));
if (set == null)
throw Error.ArgumentNull("set");
throw Error.ArgumentNull(nameof(set));

this.getPath = XPathCompiler.Compile(get);
this.setPath = XPathCompiler.Compile(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ private DictionaryAdapterMeta InternalGetAdapterMeta(Type type,
PropertyDescriptor descriptor, DictionaryAdapterMeta other)
{
if (type == null)
throw new ArgumentNullException("type");
throw new ArgumentNullException(nameof(type));
if (type.IsInterface == false)
throw new ArgumentException("Only interfaces can be adapted to a dictionary", "type");
throw new ArgumentException("Only interfaces can be adapted to a dictionary", nameof(type));

return interfaceToMeta.GetOrAdd(type, t =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public IEnumerable<IDictionaryCopyStrategy> CopyStrategies
public void AddCopyStrategy(IDictionaryCopyStrategy copyStrategy)
{
if (copyStrategy == null)
throw new ArgumentNullException("copyStrategy");
throw new ArgumentNullException(nameof(copyStrategy));

if (copyStrategies == null)
copyStrategies = new List<IDictionaryCopyStrategy>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static string GetKey(object key)
{
if (key == null)
{
throw new ArgumentNullException("key");
throw new ArgumentNullException(nameof(key));
}
return key.ToString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override bool Contains(object key)
{
if (key == null)
{
throw new ArgumentNullException("key");
throw new ArgumentNullException(nameof(key));
}

//Getting a value out is O(1), so in the case that the collection contains a non-null value for this key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public BindingList(IList<T> list)
public BindingList(SCM.BindingList<T> list)
{
if (list == null)
throw new ArgumentNullException("list");
throw new ArgumentNullException(nameof(list));

this.list = list;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ListProjection<T> :
public ListProjection(ICollectionAdapter<T> adapter)
{
if (adapter == null)
throw new ArgumentNullException("adapter");
throw new ArgumentNullException(nameof(adapter));

this.adapter = adapter;
adapter.Initialize(this);
Expand Down Expand Up @@ -262,11 +262,11 @@ int IList.Add(object item)
public void Insert(int index, T item)
{
if (index < 0)
throw new ArgumentOutOfRangeException("index");
throw new ArgumentOutOfRangeException(nameof(index));

var count = Count;
if (index > count)
throw new ArgumentOutOfRangeException("index");
throw new ArgumentOutOfRangeException(nameof(index));

EndNew(addNewIndex);
if (index == count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class ListProjectionDebugView<T>
public ListProjectionDebugView(ListProjection<T> projection)
{
if (projection == null)
throw new ArgumentNullException("projection");
throw new ArgumentNullException(nameof(projection));

this.projection = projection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public XmlAdapter()
public XmlAdapter(XmlNode node)
{
if (node == null)
throw Error.ArgumentNull("node");
throw Error.ArgumentNull(nameof(node));

this.source = node;
this.isRoot = true;
Expand All @@ -60,9 +60,9 @@ public XmlAdapter(XmlNode node)
public XmlAdapter(IXmlNode node, XmlReferenceManager references)
{
if (node == null)
throw Error.ArgumentNull("node");
throw Error.ArgumentNull(nameof(node));
if (references == null)
throw Error.ArgumentNull("references");
throw Error.ArgumentNull(nameof(references));

this.node = node;
this.references = references;
Expand Down Expand Up @@ -455,30 +455,30 @@ public static XmlAdapter For(object obj, bool required)
{
if (obj == null)
if (!required) return null;
else throw Error.ArgumentNull("obj");
else throw Error.ArgumentNull(nameof(obj));

var dictionaryAdapter = obj as IDictionaryAdapter;
if (dictionaryAdapter == null)
if (!required) return null;
else throw Error.NotDictionaryAdapter("obj");
else throw Error.NotDictionaryAdapter(nameof(obj));

var descriptor = dictionaryAdapter.This.Descriptor;
if (descriptor == null)
if (!required) return null;
else throw Error.NoInstanceDescriptor("obj");
else throw Error.NoInstanceDescriptor(nameof(obj));

var getters = descriptor.Getters;
if (getters == null)
if (!required) return null;
else throw Error.NoXmlAdapter("obj");
else throw Error.NoXmlAdapter(nameof(obj));

XmlAdapter xmlAdapter;
foreach (var getter in getters)
if (null != (xmlAdapter = getter as XmlAdapter))
return xmlAdapter;

if (!required) return null;
else throw Error.NoXmlAdapter("obj");
else throw Error.NoXmlAdapter(nameof(obj));
}

public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public class XmlMetadata : IXmlKnownType, IXmlKnownTypeMap, IXmlIncludedType, IX
public XmlMetadata(DictionaryAdapterMeta meta, IEnumerable<string> reservedNamespaceUris)
{
if (meta == null)
throw Error.ArgumentNull("meta");
throw Error.ArgumentNull(nameof(meta));
if (reservedNamespaceUris == null)
throw Error.ArgumentNull("reservedNamespaceUris");
throw Error.ArgumentNull(nameof(reservedNamespaceUris));

source = meta;
clrType = meta.Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public bool TryGet(object keyObject, out object inGraphObject)
public void Add(IXmlNode node, object keyValue, object newValue, bool isInGraph)
{
if (keyValue == null)
throw Error.ArgumentNull("keyValue");
throw Error.ArgumentNull(nameof(keyValue));
if (newValue == null)
throw Error.ArgumentNull("newValue");
throw Error.ArgumentNull(nameof(newValue));

var type = newValue.GetComponentType();
if (ShouldExclude(type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public abstract class XmlAccessor : IXmlPropertyAccessor, IXmlCollectionAccessor
protected XmlAccessor(Type clrType, IXmlContext context)
{
if (clrType == null)
throw Error.ArgumentNull("clrType");
throw Error.ArgumentNull(nameof(clrType));
if (context == null)
throw Error.ArgumentNull("context");
throw Error.ArgumentNull(nameof(context));

clrType = clrType.NonNullable();
this.clrType = clrType;
Expand Down Expand Up @@ -121,7 +121,7 @@ protected IXmlContext CloneContext()
private void SetContext(IXmlContext value)
{
if (null == value)
throw Error.ArgumentNull("value");
throw Error.ArgumentNull(nameof(value));

context = value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected XmlNodeAccessor(string name, Type type, IXmlContext context)
: base(type, context)
{
if (name == null)
throw Error.ArgumentNull("name");
throw Error.ArgumentNull(nameof(name));
if (name == string.Empty)
throw Error.InvalidLocalName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class XmlContext : XmlContextBase, IXmlContext
public XmlContext(XmlMetadata metadata)
{
if (metadata == null)
throw Error.ArgumentNull("metadata");
throw Error.ArgumentNull(nameof(metadata));

this.metadata = metadata;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override string ToString()
public static XmlName ParseQName(string text)
{
if (text == null)
throw Error.ArgumentNull("text");
throw Error.ArgumentNull(nameof(text));

var index = text.IndexOf(':');
if (index == -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public abstract class XmlNodeBase : IRealizableSource, IVirtual
protected XmlNodeBase(IXmlNamespaceSource namespaces, IXmlNode parent)
{
if (null == namespaces)
throw Error.ArgumentNull("namespaces");
throw Error.ArgumentNull(nameof(namespaces));

this.namespaces = namespaces;
this.parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public SysXmlCursor(IXmlNode parent, IXmlKnownTypeMap knownTypes, IXmlNamespaceS
: base(namespaces, parent)
{
if (null == parent)
throw Error.ArgumentNull("parent");
throw Error.ArgumentNull(nameof(parent));
if (null == knownTypes)
throw Error.ArgumentNull("knownTypes");
throw Error.ArgumentNull(nameof(knownTypes));

this.knownTypes = knownTypes;
this.flags = flags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public SysXmlNode(XmlNode node, Type type, IXmlNamespaceSource namespaces)
: base(namespaces, null)
{
if (node == null)
throw Error.ArgumentNull("node");
throw Error.ArgumentNull(nameof(node));
if (type == null)
throw Error.ArgumentNull("type");
throw Error.ArgumentNull(nameof(type));

this.node = node;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SysXmlSubtreeIterator(IXmlNode parent, IXmlNamespaceSource namespaces)
: base(namespaces, parent)
{
if (null == parent)
throw Error.ArgumentNull("parent");
throw Error.ArgumentNull(nameof(parent));

var source = parent.RequireRealizable<XmlNode>();
if (source.IsReal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class XPathCompiler
public static CompiledXPath Compile(string path)
{
if (null == path)
throw Error.ArgumentNull("path");
throw Error.ArgumentNull(nameof(path));

// Compile whole path to catch errors
var result = new CompiledXPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class XPathExtensions
public static XPathNavigator CreateNavigatorSafe(this IXPathNavigable source)
{
if (source == null)
throw Error.ArgumentNull("source");
throw Error.ArgumentNull(nameof(source));
return source.CreateNavigator();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public XPathMutableCursor(IXmlNode parent, CompiledXPath path,
: base(path, namespaces, parent)
{
if (null == parent)
throw Error.ArgumentNull("parent");
throw Error.ArgumentNull(nameof(parent));
if (null == path)
throw Error.ArgumentNull("path");
throw Error.ArgumentNull(nameof(path));
if (null == knownTypes)
throw Error.ArgumentNull("knownTypes");
throw Error.ArgumentNull(nameof(knownTypes));
if (!path.IsCreatable)
throw Error.XPathNotCreatable(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public XPathNode(XPathNavigator node, Type type, IXmlNamespaceSource namespaces)
: this(null, namespaces, null)
{
if (node == null)
throw Error.ArgumentNull("node");
throw Error.ArgumentNull(nameof(node));
if (type == null)
throw Error.ArgumentNull("type");
throw Error.ArgumentNull(nameof(type));

this.node = node;
this.type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public XPathReadOnlyCursor(IXmlNode parent, CompiledXPath path,
: base(path, namespaces, parent)
{
if (parent == null)
throw Error.ArgumentNull("parent");
throw Error.ArgumentNull(nameof(parent));
if (path == null)
throw Error.ArgumentNull("path");
throw Error.ArgumentNull(nameof(path));
if (includedTypes == null)
throw Error.ArgumentNull("includedTypes");
throw Error.ArgumentNull(nameof(includedTypes));

this.includedTypes = includedTypes;
this.flags = flags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAcce
// Require a dictionary adapter
var source = value as IDictionaryAdapter;
if (source == null)
throw Error.NotDictionaryAdapter("value");
throw Error.NotDictionaryAdapter(nameof(value));

// Detect assignment of own value
var sourceAdapter = XmlAdapter.For(source, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public XmlIncludedType(XmlName xsiType, Type clrType)
if (xsiType.LocalName == null)
throw Error.ArgumentNull("xsiType.LocalName");
if (clrType == null)
throw Error.ArgumentNull("clrType");
throw Error.ArgumentNull(nameof(clrType));

this.xsiType = xsiType;
this.clrType = clrType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public XmlKnownType(XmlName name, XmlName xsiType, Type clrType)
if (name.LocalName == null)
throw Error.ArgumentNull("name.LocalName");
if (clrType == null)
throw Error.ArgumentNull("clrType");
throw Error.ArgumentNull(nameof(clrType));

this.name = name;
this.xsiType = xsiType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class XmlKnownTypeSet : IXmlKnownTypeMap, IEnumerable<IXmlKnownType>
public XmlKnownTypeSet(Type defaultType)
{
if (defaultType == null)
throw Error.ArgumentNull("defaultType");
throw Error.ArgumentNull(nameof(defaultType));

itemsByXmlIdentity = new Dictionary<IXmlIdentity, IXmlKnownType>(XmlIdentityComparer.Instance);
itemsByClrType = new Dictionary<Type, IXmlKnownType>();
Expand Down
Loading

0 comments on commit f2a75e0

Please sign in to comment.