Util method to cache a Type for JSON serialization

This commit is contained in:
Chris Cameron
2018-02-16 14:39:43 -05:00
parent a710e4f052
commit b62b5661e5
2 changed files with 30 additions and 2 deletions

View File

@@ -210,6 +210,26 @@ namespace ICD.Common.Utils
: null;
}
/// <summary>
/// Returns true if the given type has a public parameterless constructor.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public static bool HasPublicParameterlessConstructor(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
const BindingFlags binding = BindingFlags.Instance | BindingFlags.Public;
#if SIMPLSHARP
return ((CType)type).GetConstructor(binding, null, new CType[0], null)
#else
return type.GetConstructor(binding, null, new Type[0], null)
#endif
!= null;
}
/// <summary>
/// Creates an instance of the given type, calling the default constructor.
/// </summary>