mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
added resource mapping validation tests
This commit is contained in:
parent
1d49435675
commit
c3214a2e88
17 changed files with 297 additions and 76 deletions
48
NzbDrone.Common/Reflection/ReflectionExtensions.cs
Normal file
48
NzbDrone.Common/Reflection/ReflectionExtensions.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NzbDrone.Common.Reflection
|
||||
{
|
||||
public static class ReflectionExtensions
|
||||
{
|
||||
public static List<PropertyInfo> GetSimpleProperties(this Type type)
|
||||
{
|
||||
var properties = type.GetProperties();
|
||||
return properties.Where(c => c.PropertyType.IsSimpleType()).ToList();
|
||||
}
|
||||
|
||||
|
||||
public static List<Type> ImplementationsOf<T>(this Assembly assembly)
|
||||
{
|
||||
return assembly.GetTypes().Where(c => typeof(T).IsAssignableFrom(c)).ToList();
|
||||
}
|
||||
|
||||
|
||||
public static bool IsSimpleType(this Type type)
|
||||
{
|
||||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
type = type.GetGenericArguments()[0];
|
||||
}
|
||||
|
||||
return type.IsPrimitive
|
||||
|| type.IsEnum
|
||||
|| type == typeof(string)
|
||||
|| type == typeof(DateTime)
|
||||
|| type == typeof(Decimal);
|
||||
}
|
||||
|
||||
public static bool IsReadable(this PropertyInfo propertyInfo)
|
||||
{
|
||||
return propertyInfo.CanRead && propertyInfo.GetGetMethod(false) != null;
|
||||
}
|
||||
|
||||
public static bool IsWritable(this PropertyInfo propertyInfo)
|
||||
{
|
||||
return propertyInfo.CanWrite && propertyInfo.GetSetMethod(false) != null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue