Skip to content

Commit

Permalink
Code cleanup - introducing the 'nameof' operator instead of string va…
Browse files Browse the repository at this point in the history
…lues
  • Loading branch information
Maxim Korsukov committed Aug 25, 2016
1 parent 727ba67 commit f6139ee
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions DocX.iOS/System/IO/Packaging/Check.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void PartUriDoesntEndWithSlash(Uri uri)
public static void Package(object package)
{
if (package == null)
throw new ArgumentNullException("package");
throw new ArgumentNullException(nameof(package));
}


Expand All @@ -78,22 +78,22 @@ public static void PackageUri(object packageUri)
public static void PackageUriIsValid(Uri packageUri)
{
if (!packageUri.IsAbsoluteUri)
throw new ArgumentException("packageUri", "Uri must be absolute");
throw new ArgumentException(nameof(packageUri), "Uri must be absolute");
}

public static void PackUriIsValid(Uri packUri)
{
if (!packUri.IsAbsoluteUri)
throw new ArgumentException("packUri", "PackUris must be absolute");
throw new ArgumentException(nameof(packUri), "PackUris must be absolute");

if (packUri.Scheme != PackUriHelper.UriSchemePack)
throw new ArgumentException("packUri", "Uri scheme is not a valid PackUri scheme");
throw new ArgumentException(nameof(packUri), "Uri scheme is not a valid PackUri scheme");
}

public static void PartUri(object partUri)
{
if (partUri == null)
throw new ArgumentNullException("partUri");
throw new ArgumentNullException(nameof(partUri));
}

public static void PartUriIsValid(Uri partUri)
Expand All @@ -108,19 +108,19 @@ public static void PartUriIsValid(Uri partUri)
public static void RelationshipTypeIsValid(string relationshipType)
{
if (relationshipType == null)
throw new ArgumentNullException("relationshipType");
throw new ArgumentNullException(nameof(relationshipType));
if (EmptyOrBlank(relationshipType))
throw new ArgumentException("relationshipType", "Cannot be whitespace or empty");
}

public static void PartUri(Uri partUri)
{
if (partUri == null)
throw new ArgumentNullException("partUri");
throw new ArgumentNullException(nameof(partUri));
if (partUri.IsAbsoluteUri)
throw new ArgumentException("partUri", "Absolute URIs are not supported");
throw new ArgumentException(nameof(partUri), "Absolute URIs are not supported");
if (string.IsNullOrEmpty(partUri.OriginalString))
throw new ArgumentException("partUri", "Part uri cannot be an empty string");
throw new ArgumentException(nameof(partUri), "Part uri cannot be an empty string");
}

public static void PackUri(Uri packUri)
Expand All @@ -143,21 +143,21 @@ public static void TargetPartUri(Uri targetPartUri)
public static void SourceUri(Uri sourceUri)
{
if (sourceUri == null)
throw new ArgumentNullException("sourceUri");
throw new ArgumentNullException(nameof(sourceUri));
// if (sourceUri.IsAbsoluteUri)
// throw new ArgumentException ("sourceUri", "Absolute URIs are not supported");
if (string.IsNullOrEmpty(sourceUri.OriginalString))
throw new ArgumentException("sourceUri", "Part uri cannot be an empty string");
throw new ArgumentException(nameof(sourceUri), "Part uri cannot be an empty string");
}

public static void TargetUri(Uri targetUri)
{
if (targetUri == null)
throw new ArgumentNullException("targetUri");
throw new ArgumentNullException(nameof(targetUri));
// if (targetUri.IsAbsoluteUri)
// throw new ArgumentException ("targetUri", "Absolute URIs are not supported");
if (string.IsNullOrEmpty(targetUri.OriginalString))
throw new ArgumentException("targetUri", "Part uri cannot be an empty string");
throw new ArgumentException(nameof(targetUri), "Part uri cannot be an empty string");
}
}
}
6 changes: 3 additions & 3 deletions DocX/Charts/XElementHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class XElementHelpers
internal static T GetValueToEnum<T>(XElement element)
{
if (element == null)
throw new ArgumentNullException("element");
throw new ArgumentNullException(nameof(element));

String value = element.Attribute(XName.Get("val")).Value;
foreach (T e in Enum.GetValues(typeof(T)))
Expand All @@ -36,7 +36,7 @@ internal static T GetValueToEnum<T>(XElement element)
internal static void SetValueFromEnum<T>(XElement element, T value)
{
if (element == null)
throw new ArgumentNullException("element");
throw new ArgumentNullException(nameof(element));
element.Attribute(XName.Get("val")).Value = GetXmlNameFromEnum<T>(value);
}

Expand All @@ -47,7 +47,7 @@ internal static void SetValueFromEnum<T>(XElement element, T value)
internal static String GetXmlNameFromEnum<T>(T value)
{
if (value == null)
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));

FieldInfo fi = typeof(T).GetField(value.ToString());
if (fi.GetCustomAttributes(typeof(XmlNameAttribute), false).Count() == 0)
Expand Down
2 changes: 1 addition & 1 deletion DocX/ExtensionsHeadings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static bool HasFlag(this Enum variable, Enum value)
return false;

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

// Not as good as the .NET 4 version of this function, but should be good enough
if (!Enum.IsDefined(variable.GetType(), value))
Expand Down
2 changes: 1 addition & 1 deletion DocX/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4619,7 +4619,7 @@ internal Text(DocX document, XElement xml, int startIndex)
internal static XElement[] SplitText(Text t, int index)
{
if (index < t.startIndex || index > t.EndIndex)
throw new ArgumentOutOfRangeException("index");
throw new ArgumentOutOfRangeException(nameof(index));

XElement splitLeft = null, splitRight = null;
if (t.Xml.Name.LocalName == "t" || t.Xml.Name.LocalName == "delText")
Expand Down
2 changes: 1 addition & 1 deletion DocX/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ public Row InsertRow(int index)
public Row InsertRow(Row row, int index)
{
if (row == null)
throw new ArgumentNullException("row");
throw new ArgumentNullException(nameof(row));

if (index < 0 || index > RowCount)
throw new IndexOutOfRangeException();
Expand Down

0 comments on commit f6139ee

Please sign in to comment.