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

@@ -9,9 +9,9 @@ namespace MediaBrowser.Model.Diagnostics
public class ProcessOptions
{
public String FileName { get; set; }
public String Arguments { get; set; }
public String WorkingDirectory { get; set; }
public string FileName { get; set; }
public string Arguments { get; set; }
public string WorkingDirectory { get; set; }
public bool CreateNoWindow { get; set; }
public bool UseShellExecute { get; set; }
public bool EnableRaisingEvents { get; set; }

View File

@@ -1,4 +1,4 @@
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.Extensions;
using System;
using System.Text.RegularExpressions;
@@ -15,7 +15,7 @@ namespace MediaBrowser.Model.Dlna
/// <param name="term">The term.</param>
/// <param name="limit">The limit.</param>
/// <returns>System.String[].</returns>
private string[] RegexSplit(string str, string term, int limit)
private static string[] RegexSplit(string str, string term, int limit)
{
return new Regex(term).Split(str, limit);
}
@@ -26,7 +26,7 @@ namespace MediaBrowser.Model.Dlna
/// <param name="str">The string.</param>
/// <param name="term">The term.</param>
/// <returns>System.String[].</returns>
private string[] RegexSplit(string str, string term)
private static string[] RegexSplit(string str, string term)
{
return Regex.Split(str, term, RegexOptions.IgnoreCase);
}
@@ -35,15 +35,15 @@ namespace MediaBrowser.Model.Dlna
{
if (string.IsNullOrEmpty(search))
{
throw new ArgumentNullException("search");
throw new ArgumentNullException(nameof(search));
}
SearchType = SearchType.Unknown;
String[] factors = RegexSplit(search, "(and|or)");
foreach (String factor in factors)
string[] factors = RegexSplit(search, "(and|or)");
foreach (string factor in factors)
{
String[] subFactors = RegexSplit(factor.Trim().Trim('(').Trim(')').Trim(), "\\s", 3);
string[] subFactors = RegexSplit(factor.Trim().Trim('(').Trim(')').Trim(), "\\s", 3);
if (subFactors.Length == 3)
{

View File

@@ -700,7 +700,7 @@ namespace MediaBrowser.Model.Dlna
{
if (item == null)
{
throw new ArgumentNullException("item");
throw new ArgumentNullException(nameof(item));
}
var transcodeReasons = new List<TranscodeReason>();

View File

@@ -153,7 +153,7 @@ namespace MediaBrowser.Model.Dlna
if (string.IsNullOrEmpty(baseUrl))
{
throw new ArgumentNullException(baseUrl);
throw new ArgumentNullException(nameof(baseUrl));
}
List<string> list = new List<string>();
@@ -195,7 +195,7 @@ namespace MediaBrowser.Model.Dlna
{
if (string.IsNullOrEmpty(baseUrl))
{
throw new ArgumentNullException(baseUrl);
throw new ArgumentNullException(nameof(baseUrl));
}
string extension = string.IsNullOrEmpty(Container) ? string.Empty : "." + Container;

View File

@@ -40,7 +40,7 @@ namespace MediaBrowser.Model.Entities
{
if (instance == null)
{
throw new ArgumentNullException("instance");
throw new ArgumentNullException(nameof(instance));
}
if (instance.ProviderIds == null)
@@ -63,7 +63,7 @@ namespace MediaBrowser.Model.Entities
{
if (instance == null)
{
throw new ArgumentNullException("instance");
throw new ArgumentNullException(nameof(instance));
}
// If it's null remove the key from the dictionary

View File

@@ -64,8 +64,8 @@ namespace MediaBrowser.Model.Extensions
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
{
if (source == null) throw new ArgumentNullException("source");
if (keySelector == null) throw new ArgumentNullException("keySelector");
if (source == null) throw new ArgumentNullException(nameof(source));
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
return DistinctByImpl(source, keySelector, comparer);
}

View File

@@ -8,7 +8,7 @@ namespace MediaBrowser.Model.Extensions
{
if (value == null)
{
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(value));
}
foreach (var item in list)

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
@@ -117,7 +117,7 @@ namespace MediaBrowser.Model.IO
/// </summary>
/// <param name="path">The path.</param>
/// <returns>Stream.</returns>
Stream OpenRead(String path);
Stream OpenRead(string path);
string DefaultDirectory { get; }
@@ -328,7 +328,7 @@ namespace MediaBrowser.Model.IO
void SetExecutable(string path);
}
//TODO Investigate if can be replaced by the one from System.IO ?
public enum FileOpenMode
{
//

View File

@@ -1,4 +1,5 @@
using System;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

View File

@@ -23,7 +23,7 @@ namespace MediaBrowser.Model.Net
return string.Equals(address.Address, Address, StringComparison.OrdinalIgnoreCase);
}
public override String ToString()
public override string ToString()
{
return Address;
}

View File

@@ -127,7 +127,7 @@ namespace MediaBrowser.Model.Net
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException("path");
throw new ArgumentNullException(nameof(path));
}
var ext = Path.GetExtension(path) ?? string.Empty;
@@ -333,7 +333,7 @@ namespace MediaBrowser.Model.Net
{
if (string.IsNullOrEmpty(mimeType))
{
throw new ArgumentNullException("mimeType");
throw new ArgumentNullException(nameof(mimeType));
}
// handle text/html; charset=UTF-8

View File

@@ -1,5 +1,6 @@
using System.Reflection;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
@@ -7,17 +8,14 @@ using System.Resources;
[assembly: AssemblyTitle("MediaBrowser.Model")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MediaBrowser.Model")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyCompany("Jellyfin Project")]
[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

View File

@@ -11,7 +11,7 @@ namespace MediaBrowser.Model.Serialization
/// </summary>
/// <param name="obj">The obj.</param>
/// <param name="stream">The stream.</param>
/// <exception cref="System.ArgumentNullException">obj</exception>
/// <exception cref="ArgumentNullException">obj</exception>
void SerializeToStream(object obj, Stream stream);
/// <summary>
@@ -19,7 +19,7 @@ namespace MediaBrowser.Model.Serialization
/// </summary>
/// <param name="obj">The obj.</param>
/// <param name="file">The file.</param>
/// <exception cref="System.ArgumentNullException">obj</exception>
/// <exception cref="ArgumentNullException">obj</exception>
void SerializeToFile(object obj, string file);
/// <summary>
@@ -28,7 +28,7 @@ namespace MediaBrowser.Model.Serialization
/// <param name="type">The type.</param>
/// <param name="file">The file.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.ArgumentNullException">type</exception>
/// <exception cref="ArgumentNullException">type</exception>
object DeserializeFromFile(Type type, string file);
/// <summary>
@@ -37,7 +37,7 @@ namespace MediaBrowser.Model.Serialization
/// <typeparam name="T"></typeparam>
/// <param name="file">The file.</param>
/// <returns>``0.</returns>
/// <exception cref="System.ArgumentNullException">file</exception>
/// <exception cref="ArgumentNullException">file</exception>
T DeserializeFromFile<T>(string file)
where T : class;
@@ -47,7 +47,7 @@ namespace MediaBrowser.Model.Serialization
/// <typeparam name="T"></typeparam>
/// <param name="stream">The stream.</param>
/// <returns>``0.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
/// <exception cref="ArgumentNullException">stream</exception>
T DeserializeFromStream<T>(Stream stream);
/// <summary>
@@ -56,7 +56,7 @@ namespace MediaBrowser.Model.Serialization
/// <typeparam name="T"></typeparam>
/// <param name="text">The text.</param>
/// <returns>``0.</returns>
/// <exception cref="System.ArgumentNullException">text</exception>
/// <exception cref="ArgumentNullException">text</exception>
T DeserializeFromString<T>(string text);
/// <summary>
@@ -65,7 +65,7 @@ namespace MediaBrowser.Model.Serialization
/// <param name="stream">The stream.</param>
/// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.ArgumentNullException">stream</exception>
/// <exception cref="ArgumentNullException">stream</exception>
object DeserializeFromStream(Stream stream, Type type);
/// <summary>
@@ -74,7 +74,7 @@ namespace MediaBrowser.Model.Serialization
/// <param name="json">The json.</param>
/// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
/// <exception cref="System.ArgumentNullException">json</exception>
/// <exception cref="ArgumentNullException">json</exception>
object DeserializeFromString(string json, Type type);
/// <summary>
@@ -82,7 +82,7 @@ namespace MediaBrowser.Model.Serialization
/// </summary>
/// <param name="obj">The obj.</param>
/// <returns>System.String.</returns>
/// <exception cref="System.ArgumentNullException">obj</exception>
/// <exception cref="ArgumentNullException">obj</exception>
string SerializeToString(object obj);
Task<object> DeserializeFromStreamAsync(Stream stream, Type type);

View File

@@ -670,7 +670,7 @@ namespace MediaBrowser.Model.Services
public static string HtmlDecode(string s)
{
if (s == null)
throw new ArgumentNullException("s");
throw new ArgumentNullException(nameof(s));
if (s.IndexOf('&') == -1)
return s;
@@ -791,7 +791,7 @@ namespace MediaBrowser.Model.Services
break;
}
if (Char.IsDigit(c))
if (char.IsDigit(c))
{
if (digit_start == 0)
digit_start = i;
@@ -845,9 +845,9 @@ namespace MediaBrowser.Model.Services
public static QueryParamCollection ParseQueryString(string query, Encoding encoding)
{
if (query == null)
throw new ArgumentNullException("query");
throw new ArgumentNullException(nameof(query));
if (encoding == null)
throw new ArgumentNullException("encoding");
throw new ArgumentNullException(nameof(encoding));
if (query.Length == 0 || (query.Length == 1 && query[0] == '?'))
return new QueryParamCollection();
if (query[0] == '?')

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Model.Dto;
@@ -20,12 +20,12 @@ namespace MediaBrowser.Model.Services
}
}
private StringComparison GetStringComparison()
private static StringComparison GetStringComparison()
{
return StringComparison.OrdinalIgnoreCase;
}
private StringComparer GetStringComparer()
private static StringComparer GetStringComparer()
{
return StringComparer.OrdinalIgnoreCase;
}
@@ -218,7 +218,7 @@ namespace MediaBrowser.Model.Services
return pair.Name + "=" + pair.Value;
}
public override String ToString()
public override string ToString()
{
var vals = this.Select(GetQueryStringValue).ToArray();