@@ -21,7 +21,7 @@ internal static IEnumerable<MethodInfo> GetCommandMethods(this Type type, bool i
2121 . Where ( m => ! typeof ( IDisposable ) . IsAssignableFrom ( type ) || m . Name != nameof ( IDisposable . Dispose ) ) ;
2222 }
2323
24- internal static bool IsNullableType ( this Type type ) => Nullable . GetUnderlyingType ( type ) != null ;
24+ private static bool IsNullableType ( this Type type ) => Nullable . GetUnderlyingType ( type ) != null ;
2525
2626 internal static bool IsNullableProperty ( this PropertyInfo propertyInfo ) =>
2727 propertyInfo . PropertyType . IsNullableType ( )
@@ -31,84 +31,63 @@ internal static bool IsNullableParameter(this ParameterInfo parameterInfo) =>
3131 parameterInfo . ParameterType . IsNullableType ( )
3232 || ( parameterInfo . GetNullability ( ) == NullabilityState . Nullable ) ;
3333
34- internal static Type GetUnderlyingType ( this Type type )
35- {
36- return Nullable . GetUnderlyingType ( type )
37- ?? type . GetListUnderlyingType ( )
38- ?? type ;
39- }
34+ internal static Type GetUnderlyingType ( this Type type ) =>
35+ Nullable . GetUnderlyingType ( type )
36+ ?? type . GetListUnderlyingType ( )
37+ ?? type ;
4038
41- internal static Type ? GetListUnderlyingType ( this Type type )
42- {
43- return type . IsArray
39+ private static Type ? GetListUnderlyingType ( this Type type ) =>
40+ type . IsArray
4441 ? type . GetElementType ( )
4542 : typeof ( IEnumerable ) . IsAssignableFrom ( type ) && type . IsGenericType
4643 ? type . GetGenericArguments ( ) . FirstOrDefault ( )
4744 : null ;
48- }
4945
5046 internal static bool IsNonStringEnumerable ( this Type type ) =>
5147 type != typeof ( string ) && type . IsEnumerable ( ) ;
5248
53- internal static bool IsEnumerable ( this Type type )
54- {
55- return type . GetInterfaces ( )
49+ private static bool IsEnumerable ( this Type type ) =>
50+ type . GetInterfaces ( )
5651 . Concat ( type . ToEnumerable ( ) )
5752 . Any ( x => x == typeof ( IEnumerable ) ) ;
58- }
5953
6054 internal static bool IsNonStringCollection ( this Type type ) =>
6155 type != typeof ( string ) && type . IsCollection ( ) ;
6256
63- internal static bool IsCollection ( this Type type )
64- {
65- return type . GetInterfaces ( )
57+ internal static bool IsCollection ( this Type type ) =>
58+ type . GetInterfaces ( )
6659 . Concat ( type . ToEnumerable ( ) )
6760 . Any ( x => x . IsGenericType
6861 ? x . GetGenericTypeDefinition ( ) == typeof ( ICollection < > )
6962 : x == typeof ( ICollection ) ) ;
70- }
7163
7264 internal static bool IsStaticClass ( this Type type ) => type . IsAbstract && type . IsSealed ;
7365
7466 private static readonly Dictionary < Type , MethodInfo > DefaultMethodByType = new ( ) ;
7567
76- internal static object ? GetDefaultValue ( this Type type )
77- {
78- return DefaultMethodByType . GetOrAdd ( type , _ =>
68+ private static object ? GetDefaultValue ( this Type type ) =>
69+ DefaultMethodByType . GetOrAdd ( type , _ =>
7970 {
8071 Func < object ? > f = GetDefaultValue < object > ;
8172 return f . Method . GetGenericMethodDefinition ( ) . MakeGenericMethod ( type ) ;
8273 } ) . Invoke ( null , null ) ;
83- }
8474
85- internal static bool IsDefaultFor ( this object defaultValue , Type type )
86- {
87- return Equals ( defaultValue , type . GetDefaultValue ( ) ) ;
88- }
75+ internal static bool IsDefaultFor ( this object defaultValue , Type type ) =>
76+ Equals ( defaultValue , type . GetDefaultValue ( ) ) ;
8977
90- private static T ? GetDefaultValue < T > ( )
91- {
92- return Box < T > . CreateDefault ( ) . Value ;
93- }
78+ private static T ? GetDefaultValue < T > ( ) => default ;
9479
95- internal static bool IsCompilerGenerated ( this Type ? t )
96- {
97- return t is not null
98- && ( t . IsDefined ( typeof ( CompilerGeneratedAttribute ) , false )
99- || IsCompilerGenerated ( t . DeclaringType ) ) ;
100- }
80+ internal static bool IsCompilerGenerated ( this Type ? t ) =>
81+ t is not null
82+ && ( t . IsDefined ( typeof ( CompilerGeneratedAttribute ) , false )
83+ || IsCompilerGenerated ( t . DeclaringType ) ) ;
10184
102- internal static IEnumerable < PropertyInfo > GetDeclaredProperties ( this Type type )
103- {
104- return type
85+ internal static IEnumerable < PropertyInfo > GetDeclaredProperties ( this Type type ) =>
86+ type
10587 . GetProperties ( BindingFlags . Public | BindingFlags . Instance )
10688 . Where ( x => ! x . PropertyType . IsCompilerGenerated ( ) ) ;
107- }
10889
109- internal static bool InheritsFrom < T > ( this Type type )
110- {
111- return typeof ( T ) . IsAssignableFrom ( type ) ;
112- }
90+ internal static bool InheritsFrom < T > ( this Type type ) =>
91+ typeof ( T ) . IsAssignableFrom ( type ) ;
11392 }
11493}
0 commit comments