removed code redundancies.

pull/4/head
kay.one 11 years ago
parent 6d3a604677
commit 9a24268ee7

@ -93,13 +93,10 @@ namespace Exceptron.Client.fastJSON
string val = "";
if (_tyname.TryGetValue(t, out val))
return val;
else
{
string s = t.AssemblyQualifiedName;
_tyname.Add(t, s);
return s;
}
}
readonly SafeDictionary<string, Type> _typecache = new SafeDictionary<string, Type>();
private Type GetTypeFromCache(string typename)
@ -107,13 +104,10 @@ namespace Exceptron.Client.fastJSON
Type val = null;
if (_typecache.TryGetValue(typename, out val))
return val;
else
{
Type t = Type.GetType(typename);
_typecache.Add(typename, t);
return t;
}
}
readonly SafeDictionary<Type, CreateObject> _constrcache = new SafeDictionary<Type, CreateObject>();
private delegate object CreateObject();
@ -126,8 +120,6 @@ namespace Exceptron.Client.fastJSON
{
return c();
}
else
{
DynamicMethod dynMethod = new DynamicMethod("_", objtype, null, true);
ILGenerator ilGen = dynMethod.GetILGenerator();
@ -137,7 +129,6 @@ namespace Exceptron.Client.fastJSON
_constrcache.Add(objtype, c);
return c();
}
}
catch (Exception exc)
{
throw new Exception(string.Format("Failed to fast create instance for type '{0}' from assemebly '{1}'",
@ -188,8 +179,6 @@ namespace Exceptron.Client.fastJSON
{
return sd;
}
else
{
sd = new SafeDictionary<string, myPropInfo>();
var pr = type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (var p in pr)
@ -204,7 +193,6 @@ namespace Exceptron.Client.fastJSON
_propertycache.Add(typename, sd);
return sd;
}
}
private myPropInfo CreateMyProp(Type t, string name)
{
@ -342,16 +330,16 @@ namespace Exceptron.Client.fastJSON
if (conversionType == typeof(int))
return (int)CreateLong((string)value);
else if (conversionType == typeof(long))
if (conversionType == typeof(long))
return CreateLong((string)value);
else if (conversionType == typeof(string))
if (conversionType == typeof(string))
return value;
else if (conversionType == typeof(Guid))
if (conversionType == typeof(Guid))
return CreateGuid((string)value);
else if (conversionType.IsEnum)
if (conversionType.IsEnum)
return CreateEnum(conversionType, (string)value);
return Convert.ChangeType(value, conversionType, CultureInfo.InvariantCulture);
@ -550,7 +538,6 @@ namespace Exceptron.Client.fastJSON
{
if (s.Length > 30)
return new Guid(s);
else
return new Guid(Convert.FromBase64String(s));
}
@ -571,7 +558,6 @@ namespace Exceptron.Client.fastJSON
if (UseUTCDateTime == false && utc == false)
return new DateTime(year, month, day, hour, min, sec);
else
return new DateTime(year, month, day, hour, min, sec, DateTimeKind.Utc).ToLocalTime();
}

@ -33,18 +33,15 @@ namespace Marr.Data.Converters
{
return true;
}
else if (val == 0)
if (val == 0)
{
return false;
}
else
{
throw new ConversionException(
string.Format(
"The BooleanCharConverter could not convert the value '{0}' to a boolean.",
dbValue));
}
}
public object ToDB(object clrValue)
{
@ -54,15 +51,12 @@ namespace Marr.Data.Converters
{
return 1;
}
else if (val == false)
if (val == false)
{
return 0;
}
else
{
return DBNull.Value;
}
}
public Type DbType
{

@ -33,18 +33,15 @@ namespace Marr.Data.Converters
{
return true;
}
else if (val == "N")
if (val == "N")
{
return false;
}
else
{
throw new ConversionException(
string.Format(
"The BooleanYNConverter could not convert the value '{0}' to a boolean.",
dbValue));
}
}
public object ToDB(object clrValue)
{
@ -54,15 +51,12 @@ namespace Marr.Data.Converters
{
return "Y";
}
else if (val == false)
if (val == false)
{
return "N";
}
else
{
return DBNull.Value;
}
}
public Type DbType
{

@ -24,7 +24,6 @@ namespace Marr.Data.Converters
{
if (dbValue == null || dbValue == DBNull.Value)
return null;
else
return Enum.ToObject(map.FieldType, (int)dbValue);
}
@ -32,7 +31,6 @@ namespace Marr.Data.Converters
{
if (clrValue == null)
return DBNull.Value;
else
return (int)clrValue;
}

@ -24,7 +24,6 @@ namespace Marr.Data.Converters
{
if (dbValue == null || dbValue == DBNull.Value)
return null;
else
return Enum.Parse(map.FieldType, (string)dbValue);
}
@ -32,7 +31,6 @@ namespace Marr.Data.Converters
{
if (clrValue == null)
return DBNull.Value;
else
return clrValue.ToString();
}

@ -65,11 +65,8 @@ namespace Marr.Data
{
return col.TryGetAltName();
}
else
{
return col.Name;
}
}
/// <summary>
/// Returns the mapped column name, or the member name.

@ -174,7 +174,6 @@ namespace Marr.Data
{
if (string.IsNullOrEmpty(sql))
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
else
Command.CommandText = sql;
try
@ -197,7 +196,6 @@ namespace Marr.Data
{
if (string.IsNullOrEmpty(sql))
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
else
Command.CommandText = sql;
try
@ -223,7 +221,6 @@ namespace Marr.Data
{
if (string.IsNullOrEmpty(sql))
throw new ArgumentNullException("sql", "A SQL query or stored procedure name is required");
else
Command.CommandText = sql;
try

@ -105,12 +105,9 @@ namespace Marr.Data
// Return entity specific column map strategy
return _columnMapStrategies[entityType];
}
else
{
// Return the default column map strategy
return _columnMapStrategies[typeof(object)];
}
}
#endregion
@ -219,22 +216,19 @@ namespace Marr.Data
// User registered type converter
return TypeConverters[dataType];
}
else if (TypeConverters.ContainsKey(typeof(Enum)) && dataType.IsEnum)
if (TypeConverters.ContainsKey(typeof(Enum)) && dataType.IsEnum)
{
// A converter is registered to handled enums
return TypeConverters[typeof(Enum)];
}
else if (TypeConverters.ContainsKey(typeof(object)))
if (TypeConverters.ContainsKey(typeof(object)))
{
// User registered default converter
return TypeConverters[typeof(object)];
}
else
{
// No conversion
return null;
}
}
#endregion

@ -109,10 +109,7 @@ namespace Marr.Data.Mapping
{
return AltName;
}
else
{
return Name;
}
}
}
}

@ -26,10 +26,7 @@ namespace Marr.Data.Mapping
{
return AltName;
}
else
{
return Name;
}
}
}
}

@ -216,11 +216,8 @@ namespace Marr.Data.Mapping
fieldName,
typeof(TEntity).Name));
}
else
{
MappedColumns.Add(columnMap);
}
}
/// <summary>
/// Throws an exception if the "current" property has not been set.

@ -153,11 +153,8 @@ namespace Marr.Data.Mapping
fieldName,
typeof(TEntity).Name));
}
else
{
Relationships.Add(relationship);
}
}
/// <summary>
/// Throws an exception if the "current" property has not been set.

@ -67,11 +67,8 @@ namespace Marr.Data.Mapping.Strategies
{
return (atts[0] as TableAttribute).Name;
}
else
{
return entityType.Name;
}
}
/// <summary>
/// Implements IMapStrategy.

@ -25,40 +25,39 @@ namespace Marr.Data.Parameters
if (type == typeof(String))
return DbType.String;
else if (type == typeof(Int32))
if (type == typeof(Int32))
return DbType.Int32;
else if (type == typeof(Decimal))
if (type == typeof(Decimal))
return DbType.Decimal;
else if (type == typeof(DateTime))
if (type == typeof(DateTime))
return DbType.DateTime;
else if (type == typeof(Boolean))
if (type == typeof(Boolean))
return DbType.Boolean;
else if (type == typeof(Int16))
if (type == typeof(Int16))
return DbType.Int16;
else if (type == typeof(Single))
if (type == typeof(Single))
return DbType.Single;
else if (type == typeof(Int64))
if (type == typeof(Int64))
return DbType.Int64;
else if (type == typeof(Double))
if (type == typeof(Double))
return DbType.Double;
else if (type == typeof(Byte))
if (type == typeof(Byte))
return DbType.Byte;
else if (type == typeof(Byte[]))
if (type == typeof(Byte[]))
return DbType.Binary;
else if (type == typeof(Guid))
if (type == typeof(Guid))
return DbType.Guid;
else
return DbType.Object;
}

@ -26,37 +26,36 @@ namespace Marr.Data.Parameters
if (type == typeof(String))
return OleDbType.VarChar;
else if (type == typeof(Int32))
if (type == typeof(Int32))
return OleDbType.Integer;
else if (type == typeof(Decimal))
if (type == typeof(Decimal))
return OleDbType.Decimal;
else if (type == typeof(DateTime))
if (type == typeof(DateTime))
return OleDbType.DBTimeStamp;
else if (type == typeof(Boolean))
if (type == typeof(Boolean))
return OleDbType.Boolean;
else if (type == typeof(Int16))
if (type == typeof(Int16))
return OleDbType.SmallInt;
else if (type == typeof(Int64))
if (type == typeof(Int64))
return OleDbType.BigInt;
else if (type == typeof(Double))
if (type == typeof(Double))
return OleDbType.Double;
else if (type == typeof(Byte))
if (type == typeof(Byte))
return OleDbType.Binary;
else if (type == typeof(Byte[]))
if (type == typeof(Byte[]))
return OleDbType.VarBinary;
else if (type == typeof(Guid))
if (type == typeof(Guid))
return OleDbType.Guid;
else
return OleDbType.Variant;
}

@ -26,40 +26,39 @@ namespace Marr.Data.Parameters
if (type == typeof(String))
return SqlDbType.VarChar;
else if (type == typeof(Int32))
if (type == typeof(Int32))
return SqlDbType.Int;
else if (type == typeof(Decimal))
if (type == typeof(Decimal))
return SqlDbType.Decimal;
else if (type == typeof(DateTime))
if (type == typeof(DateTime))
return SqlDbType.DateTime;
else if (type == typeof(Boolean))
if (type == typeof(Boolean))
return SqlDbType.Bit;
else if (type == typeof(Int16))
if (type == typeof(Int16))
return SqlDbType.SmallInt;
else if (type == typeof(Int64))
if (type == typeof(Int64))
return SqlDbType.BigInt;
else if (type == typeof(Double))
if (type == typeof(Double))
return SqlDbType.Float;
else if (type == typeof(Char))
if (type == typeof(Char))
return SqlDbType.Char;
else if (type == typeof(Byte))
if (type == typeof(Byte))
return SqlDbType.Binary;
else if (type == typeof(Byte[]))
if (type == typeof(Byte[]))
return SqlDbType.VarBinary;
else if (type == typeof(Guid))
if (type == typeof(Guid))
return SqlDbType.UniqueIdentifier;
else
return SqlDbType.Variant;
}

@ -32,11 +32,8 @@ namespace Marr.Data.QGen
{
return ComplexPaging();
}
else
{
return SimplePaging();
}
}
/// <summary>
/// Generates a query that pages a simple inner query.

@ -18,11 +18,8 @@ namespace Marr.Data.QGen
{
return ComplexRowCount();
}
else
{
return SimpleRowCount();
}
}
/// <summary>
/// Generates a row count query for a multiple table joined query (groups by the parent entity).

@ -95,11 +95,8 @@ namespace Marr.Data.QGen
{
return columnInfo.AltName;
}
else
{
return columnInfo.Name;
}
}
public void BuildFromClause(StringBuilder sql)
{

@ -32,11 +32,8 @@ namespace Marr.Data.QGen
{
return ComplexPaging();
}
else
{
return SimplePaging();
}
}
private string SimplePaging()
{

@ -281,12 +281,9 @@ namespace Marr.Data.QGen
{
return _sb.ToString();
}
else
{
return _constantWhereClause;
}
}
}
internal enum WhereAppendType
{

@ -32,15 +32,12 @@ namespace Marr.Data.Reflection
{
return null;
}
else if (fieldType.IsValueType)
if (fieldType.IsValueType)
{
return Activator.CreateInstance(fieldType);
}
else
{
return null;
}
}
/// <summary>
/// Gets the CLR data type of a MemberInfo.

@ -11,11 +11,11 @@ namespace NzbDrone.Common
private const string NZBDRONE_LOG_DB = "logs.db";
private const string BACKUP_ZIP_FILE = "NzbDrone_Backup.zip";
private const string NLOG_CONFIG_FILE = "nlog.config";
private const string UPDATE_CLIENT_EXE = "nzbdrone.update.exe";
private static readonly string UPDATE_SANDBOX_FOLDER_NAME = "nzbdrone_update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_PACKAGE_FOLDER_NAME = "nzbdrone" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_BACKUP_FOLDER_NAME = "nzbdrone_backup" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_CLIENT_EXE = "nzbdrone.update.exe";
private static readonly string UPDATE_CLIENT_FOLDER_NAME = "NzbDrone.Update" + Path.DirectorySeparatorChar;
private static readonly string UPDATE_LOG_FOLDER_NAME = "UpdateLogs" + Path.DirectorySeparatorChar;

@ -118,12 +118,9 @@ namespace NzbDrone.Core.Notifications.Xbmc
return null;
}
else
{
var matchingSeries = allSeries.FirstOrDefault(s => s.ImdbNumber == series.TvdbId || s.Label == series.Title);
if (matchingSeries != null) return matchingSeries.File;
}
return null;
}

Loading…
Cancel
Save