PropertyInfoExt.cs 657 B

123456789101112131415161718192021
  1. using System;
  2. using System.Reflection;
  3. namespace Quadarax.Foundation.Core.Reflection.Extensions
  4. {
  5. public static class PropertyInfoExt
  6. {
  7. public static Type GetFinalPropertyType(this PropertyInfo owner)
  8. {
  9. if (owner == null) throw new ArgumentNullException(nameof(owner));
  10. var propertyType = owner.PropertyType;
  11. if (propertyType.IsGenericType &&
  12. propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
  13. {
  14. propertyType = propertyType.GetGenericArguments()[0];
  15. }
  16. return propertyType;
  17. }
  18. }
  19. }