Skip to content

Commit

Permalink
Use the nameof operator instead of string literals as exception ctor …
Browse files Browse the repository at this point in the history
…arguments

References #23
  • Loading branch information
andreashuber-lawo committed May 3, 2016
1 parent 0c914ce commit db681f0
Show file tree
Hide file tree
Showing 48 changed files with 100 additions and 99 deletions.
10 changes: 5 additions & 5 deletions Lawo.EmberPlusSharp/Ember/EmberConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public EmberConverter(EmberTypeBag types)
{
if (types == null)
{
throw new ArgumentNullException("types");
throw new ArgumentNullException(nameof(types));
}

this.typeNames = types.TypeNames;
Expand Down Expand Up @@ -65,12 +65,12 @@ public void ToXml(EmberReader reader, XmlWriter writer)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
throw new ArgumentNullException(nameof(reader));
}

if (writer == null)
{
throw new ArgumentNullException("writer");
throw new ArgumentNullException(nameof(writer));
}

this.ToXmlCore(reader, writer, default(FieldPath<int, EmberId>), EmberGlobal.InnerNumber);
Expand Down Expand Up @@ -103,12 +103,12 @@ public void FromXml(XmlReader reader, EmberWriter writer)
{
if (reader == null)
{
throw new ArgumentNullException("reader");
throw new ArgumentNullException(nameof(reader));
}

if (writer == null)
{
throw new ArgumentNullException("writer");
throw new ArgumentNullException(nameof(writer));
}

this.FromXmlCore(reader, writer, default(FieldPath<string, string>), EmberGlobal.Name);
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Ember/EmberId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ internal EmberId(Class theClass, bool isConstructed, int number)
{
if (number < 0)
{
throw new ArgumentOutOfRangeException("number", ExceptionMessages.NonnegativeNumberRequired);
throw new ArgumentOutOfRangeException(nameof(number), ExceptionMessages.NonnegativeNumberRequired);
}

this.theClass = theClass;
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Ember/EmberReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public EmberReader(Stream stream, int bufferSize)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
throw new ArgumentNullException(nameof(stream));
}

this.readBuffer = new ReadBuffer(stream.Read, bufferSize);
Expand Down Expand Up @@ -406,7 +406,7 @@ public object CopyToEndContainer(EmberWriter writer, EmberId? outerId)
{
if (writer == null)
{
throw new ArgumentNullException("writer");
throw new ArgumentNullException(nameof(writer));
}

object result = null;
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Ember/EmberType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public EmberType(params Type[] types)
{
if (types == null)
{
throw new ArgumentNullException("types");
throw new ArgumentNullException(nameof(types));
}

if (types.Length == 0)
{
throw new ArgumentException("Length must not be 0.", "types");
throw new ArgumentException("Length must not be 0.", nameof(types));
}

this.types = types;
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Ember/EmberTypeBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public EmberTypeBag(params EmberType[] types)
{
if (types == null)
{
throw new ArgumentNullException("types");
throw new ArgumentNullException(nameof(types));
}

var allTypes = BerTypes.Concat(types).ToArray();
Expand Down
10 changes: 5 additions & 5 deletions Lawo.EmberPlusSharp/Ember/EmberWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public EmberWriter(Stream stream, int bufferSize)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
throw new ArgumentNullException(nameof(stream));
}

this.writeBuffer = new WriteBuffer(stream.Write, bufferSize);
Expand Down Expand Up @@ -99,7 +99,7 @@ public void WriteValue(EmberId outer, byte[] value)

if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

// For byte[] values, the buffer size does not matter
Expand Down Expand Up @@ -143,7 +143,7 @@ public void WriteValue(EmberId outer, string value)

if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

var byteCount = Encoding.UTF8.GetByteCount(value);
Expand All @@ -162,7 +162,7 @@ public void WriteValue(EmberId outer, int[] value)

if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

// For byte[] values, the buffer size does not matter
Expand Down Expand Up @@ -219,7 +219,7 @@ public void WriteStartApplicationDefinedType(EmberId outer, int innerNumber)
if (innerNumber < InnerNumber.FirstApplication)
{
throw new ArgumentOutOfRangeException(
"innerNumber", "Must be greater than or equal to InnerNumber.StartFirstApplication");
nameof(innerNumber), "Must be greater than or equal to InnerNumber.StartFirstApplication");
}

this.writeBuffer.Reserve(IdentifiersAndLengthsMaxLength);
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Ember/FieldPath`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal static FieldPath<TTypeId, TFieldId> Append(
{
if (path.field1.HasValue)
{
throw new ArgumentException("Cannot be appended.", "path");
throw new ArgumentException("Cannot be appended.", nameof(path));
}

return new FieldPath<TTypeId, TFieldId>(path.field2, path.field3, field);
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Glow/GlowLogConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Convert(XmlReader logReader, XmlWriter logWriter)
{
if (logWriter == null)
{
throw new ArgumentNullException("logWriter");
throw new ArgumentNullException(nameof(logWriter));
}

var interpreter = new GlowLogInterpreter(GlowTypes.Instance, logReader);
Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/Consumer`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ public static async Task<Consumer<TRoot>> CreateAsync(
{
if (client == null)
{
throw new ArgumentNullException("client");
throw new ArgumentNullException(nameof(client));
}

if ((childrenRetrievalPolicy < ChildrenRetrievalPolicy.None) ||
(childrenRetrievalPolicy > ChildrenRetrievalPolicy.All))
{
throw new ArgumentOutOfRangeException("childrenRetrievalPolicy");
throw new ArgumentOutOfRangeException(nameof(childrenRetrievalPolicy));
}

var result = new Consumer<TRoot>(client, timeout, childrenRetrievalPolicy, slot);
Expand Down Expand Up @@ -161,7 +161,7 @@ public int AutoSendInterval
{
if (value < Timeout.Infinite)
{
throw new ArgumentOutOfRangeException("value", "Must be >= -1.");
throw new ArgumentOutOfRangeException(nameof(value), "Must be >= -1.");
}

this.autoSendInterval = value;
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/DynamicParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal sealed override object AssertValueType(object value)
catch (InvalidCastException ex)
{
throw new ArgumentException(
"The type of value does not match the type of the parameter.", "value", ex);
"The type of value does not match the type of the parameter.", nameof(value), ex);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/ElementAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public string Identifier
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

this.identifier = value;
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/FieldNode`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected FieldNode()
private static Dictionary<string, MetaElement> metaChildren;

private static Dictionary<string, MetaElement> MetaChildren =>
LazyInitializer.EnsureInitialized(ref metaChildren, GetMetaChildren);
LazyInitializer.EnsureInitialized(ref metaChildren, GetMetaChildren);

private static Dictionary<string, MetaElement> GetMetaChildren()
{
Expand Down
6 changes: 3 additions & 3 deletions Lawo.EmberPlusSharp/Model/NodeBase`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ChildrenRetrievalPolicy ChildrenRetrievalPolicy
{
if ((value < ChildrenRetrievalPolicy.None) || (value > ChildrenRetrievalPolicy.All))
{
throw new ArgumentOutOfRangeException("value");
throw new ArgumentOutOfRangeException(nameof(value));
}

if (value != this.childrenRetrievalPolicy)
Expand All @@ -45,7 +45,7 @@ public ChildrenRetrievalPolicy ChildrenRetrievalPolicy
{
throw new ArgumentException(
"A new value cannot be set if the current value is not equal to ChildrenRetrievalPolicy.None.",
"value");
nameof(value));
}

this.SetRetrieveDetailsChangeStatus(() => this.SetValue(ref this.childrenRetrievalPolicy, value));
Expand Down Expand Up @@ -93,7 +93,7 @@ internal NodeBase()
}

internal sealed override bool RetrieveDetails =>
(this.ChildrenRetrievalPolicy != ChildrenRetrievalPolicy.None) && base.RetrieveDetails;
(this.ChildrenRetrievalPolicy != ChildrenRetrievalPolicy.None) && base.RetrieveDetails;

internal sealed override void SetContext(Context context)
{
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/Model/Node`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public IElement GetElement(string path)
{
if (path == null)
{
throw new ArgumentNullException("path");
throw new ArgumentNullException(nameof(path));
}

return this.GetElement(path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries), 0);
Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/ParameterBase`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal TValue ValueCore
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}

this.SetConsumerValue(ref this.theValue, value, "Value");
Expand Down Expand Up @@ -194,7 +194,7 @@ internal virtual TValue AssertValueType(object value)
catch (InvalidCastException ex)
{
throw new ArgumentException(
"The type of value does not match the type of the parameter.", "value", ex);
"The type of value does not match the type of the parameter.", nameof(value), ex);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Lawo.EmberPlusSharp/Model/StaticFunction`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ internal sealed override KeyValuePair<string, ParameterType> ReadTupleItemDescri
private static KeyValuePair<string, ParameterType>[] resultTemplate;

private static KeyValuePair<string, ParameterType>[] ArgumentsTemplate =>
LazyInitializer.EnsureInitialized(ref argumentsTemplate, CreateArgumentsTemplate);
LazyInitializer.EnsureInitialized(ref argumentsTemplate, CreateArgumentsTemplate);

private static KeyValuePair<string, ParameterType>[] ResultTemplate =>
LazyInitializer.EnsureInitialized(ref resultTemplate, CreateResultTemplate);
LazyInitializer.EnsureInitialized(ref resultTemplate, CreateResultTemplate);

private static KeyValuePair<string, ParameterType>[] CreateArgumentsTemplate()
{
Expand Down
10 changes: 5 additions & 5 deletions Lawo.EmberPlusSharp/S101/S101Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,22 @@ public S101Client(

if (connection == null)
{
throw new ArgumentNullException("connection");
throw new ArgumentNullException(nameof(connection));
}

if (readAsync == null)
{
throw new ArgumentNullException("readAsync");
throw new ArgumentNullException(nameof(readAsync));
}

if (writeAsync == null)
{
throw new ArgumentNullException("writeAsync");
throw new ArgumentNullException(nameof(writeAsync));
}

if (timeout < -1)
{
throw new ArgumentOutOfRangeException("timeout", "A number >= -1 is required.");
throw new ArgumentOutOfRangeException(nameof(timeout), "A number >= -1 is required.");
}

WriteAsyncCallback writeAsyncWithLog;
Expand Down Expand Up @@ -412,7 +412,7 @@ await this.sendQueue.Enqueue(
{
throw new ArgumentException(
"The payload requirements of the command of the passed message do not match the passed payload.",
"payload");
nameof(payload));
}

if (payload != null)
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/S101/S101LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public S101LogReader(EmberTypeBag types, XmlReader logReader)
{
if (logReader == null)
{
throw new ArgumentNullException("logReader");
throw new ArgumentNullException(nameof(logReader));
}

this.converter = new EmberConverter(types);
Expand Down
12 changes: 6 additions & 6 deletions Lawo.EmberPlusSharp/S101/S101Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ public S101Logger(IEmberConverter converter, XmlWriter xmlLogWriter)
{
if (converter == null)
{
throw new ArgumentNullException("converter");
throw new ArgumentNullException(nameof(converter));
}

if (xmlLogWriter == null)
{
throw new ArgumentNullException("xmlLogWriter");
throw new ArgumentNullException(nameof(xmlLogWriter));
}

this.converter = converter;
Expand Down Expand Up @@ -114,7 +114,7 @@ public EventInfo LogException(string direction, Exception exception)
{
if (exception == null)
{
throw new ArgumentNullException("exception");
throw new ArgumentNullException(nameof(exception));
}

var info = new EventInfo(this.WriteStartEvent(LogNames.Exception));
Expand All @@ -137,12 +137,12 @@ internal EventInfo LogMessage(DateTime timeUtc, string direction, S101Message me
{
if (message == null)
{
throw new ArgumentNullException("message");
throw new ArgumentNullException(nameof(message));
}

if (direction == null)
{
throw new ArgumentNullException("direction");
throw new ArgumentNullException(nameof(direction));
}

this.WriteStartEvent(LogNames.Message, timeUtc);
Expand Down Expand Up @@ -173,7 +173,7 @@ private static TextWriter ValidateLogWriter(TextWriter logWriter)
{
if (logWriter == null)
{
throw new ArgumentNullException("logWriter");
throw new ArgumentNullException(nameof(logWriter));
}

return logWriter;
Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/S101/S101Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public S101Message(byte slot, S101Command command)
{
if (command == null)
{
throw new ArgumentNullException("command");
throw new ArgumentNullException(nameof(command));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Lawo.EmberPlusSharp/S101/S101Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private S101Robot(S101Client client, EmberTypeBag types, XmlReader logReader, bo
{
if (client == null)
{
throw new ArgumentNullException("client");
throw new ArgumentNullException(nameof(client));
}

this.client = client;
Expand Down
Loading

0 comments on commit db681f0

Please sign in to comment.