Mayor code cleanup

Add Argument*Exceptions now use proper nameof operators.

Added exception messages to quite a few Argument*Exceptions.

Fixed rethorwing to be proper syntax.

Added a ton of null checkes. (This is only a start, there are about 500 places that need proper null handling)

Added some TODOs to log certain exceptions.

Fix sln again.

Fixed all AssemblyInfo's and added proper copyright (where I could find them)

We live in *current year*.

Fixed the use of braces.

Fixed a ton of properties, and made a fair amount of functions static that should be and can be static.

Made more Methods that should be static static.

You can now use static to find bad functions!

Removed unused variable. And added one more proper XML comment.
This commit is contained in:
Erwin de Haan
2019-01-06 21:50:43 +01:00
parent 3d867c2c46
commit ec1f5dc317
334 changed files with 1632 additions and 2603 deletions

View File

@@ -50,7 +50,7 @@ namespace Emby.Server.Implementations.Services
public Type ServiceType { get; private set; }
public string Path { get { return this.restPath; } }
public string Path => this.restPath;
public string Summary { get; private set; }
public string Description { get; private set; }
@@ -58,10 +58,7 @@ namespace Emby.Server.Implementations.Services
public int Priority { get; set; } //passed back to RouteAttribute
public IEnumerable<string> PathVariables
{
get { return this.variablesNames.Where(e => !string.IsNullOrWhiteSpace(e)); }
}
public IEnumerable<string> PathVariables => this.variablesNames.Where(e => !string.IsNullOrWhiteSpace(e));
public static string[] GetPathPartsForMatching(string pathInfo)
{
@@ -117,8 +114,9 @@ namespace Emby.Server.Implementations.Services
var hasSeparators = new List<bool>();
foreach (var component in this.restPath.Split(PathSeperatorChar))
{
if (String.IsNullOrEmpty(component)) continue;
if (string.IsNullOrEmpty(component)) continue;
if (StringContains(component, VariablePrefix)
&& component.IndexOf(ComponentSeperator) != -1)
{
@@ -420,10 +418,10 @@ namespace Emby.Server.Implementations.Services
return pathIx == withPathInfoParts.Length;
}
private bool LiteralsEqual(string str1, string str2)
private static bool LiteralsEqual(string str1, string str2)
{
// Most cases
if (String.Equals(str1, str2, StringComparison.OrdinalIgnoreCase))
if (string.Equals(str1, str2, StringComparison.OrdinalIgnoreCase))
{
return true;
}
@@ -433,7 +431,7 @@ namespace Emby.Server.Implementations.Services
str2 = str2.ToUpperInvariant();
// Invariant IgnoreCase would probably be better but it's not available in PCL
return String.Equals(str1, str2, StringComparison.CurrentCultureIgnoreCase);
return string.Equals(str1, str2, StringComparison.CurrentCultureIgnoreCase);
}
private bool ExplodeComponents(ref string[] withPathInfoParts)
@@ -442,7 +440,7 @@ namespace Emby.Server.Implementations.Services
for (var i = 0; i < withPathInfoParts.Length; i++)
{
var component = withPathInfoParts[i];
if (String.IsNullOrEmpty(component)) continue;
if (string.IsNullOrEmpty(component)) continue;
if (this.PathComponentsCount != this.TotalComponentsCount
&& this.componentsWithSeparators[i])
@@ -473,7 +471,7 @@ namespace Emby.Server.Implementations.Services
&& requestComponents.Length >= this.TotalComponentsCount - this.wildcardCount;
if (!isValidWildCardPath)
throw new ArgumentException(String.Format(
throw new ArgumentException(string.Format(
"Path Mismatch: Request Path '{0}' has invalid number of components compared to: '{1}'",
pathInfo, this.restPath));
}
@@ -492,7 +490,7 @@ namespace Emby.Server.Implementations.Services
string propertyNameOnRequest;
if (!this.propertyNamesMap.TryGetValue(variableName.ToLower(), out propertyNameOnRequest))
{
if (String.Equals("ignore", variableName, StringComparison.OrdinalIgnoreCase))
if (string.Equals("ignore", variableName, StringComparison.OrdinalIgnoreCase))
{
pathIx++;
continue;
@@ -522,12 +520,12 @@ namespace Emby.Server.Implementations.Services
// hits a match for the next element in the definition (which must be a literal)
// It may consume 0 or more path parts
var stopLiteral = i == this.TotalComponentsCount - 1 ? null : this.literalsToMatch[i + 1];
if (!String.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
if (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
{
var sb = new StringBuilder();
sb.Append(value);
pathIx++;
while (!String.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
while (!string.Equals(requestComponents[pathIx], stopLiteral, StringComparison.OrdinalIgnoreCase))
{
sb.Append(PathSeperatorChar + requestComponents[pathIx++]);
}