1
1
using System . Collections . Generic ;
2
- using System . Threading ;
2
+ using System . Linq ;
3
+ using Unity . Attributes ;
3
4
5
+ #if NET40
4
6
namespace System . Reflection
5
7
{
6
- #if NET40
8
+ using Unity ;
9
+
7
10
internal class TypeInfo
8
11
{
9
12
private const BindingFlags DeclaredOnlyLookup = BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . Static | BindingFlags . DeclaredOnly ;
10
- private Type _type ;
13
+ private readonly Type _type ;
11
14
12
15
13
16
internal TypeInfo ( Type type )
@@ -46,6 +49,8 @@ internal TypeInfo(Type type)
46
49
47
50
public bool ContainsGenericParameters => _type . ContainsGenericParameters ;
48
51
52
+ public bool IsConstructedGenericType => _type . IsGenericType && ! _type . ContainsGenericParameters ;
53
+
49
54
#region moved over from Type
50
55
51
56
//// Fields
@@ -72,17 +77,10 @@ public virtual IEnumerable<MethodInfo> GetDeclaredMethods(String name)
72
77
}
73
78
}
74
79
75
- public virtual System . Reflection . TypeInfo GetDeclaredNestedType ( String name )
80
+ public virtual TypeInfo GetDeclaredNestedType ( String name )
76
81
{
77
82
var nt = _type . GetNestedType ( name , DeclaredOnlyLookup ) ;
78
- if ( nt == null )
79
- {
80
- return null ; //the extension method GetTypeInfo throws for null
81
- }
82
- else
83
- {
84
- return nt . GetTypeInfo ( ) ;
85
- }
83
+ return nt == null ? null : nt . GetTypeInfo ( ) ;
86
84
}
87
85
88
86
public virtual PropertyInfo GetDeclaredProperty ( String name )
@@ -93,46 +91,17 @@ public virtual PropertyInfo GetDeclaredProperty(String name)
93
91
94
92
//// Properties
95
93
96
- public virtual IEnumerable < ConstructorInfo > DeclaredConstructors
97
- {
98
- get
99
- {
100
- return _type . GetConstructors ( DeclaredOnlyLookup ) ;
101
- }
102
- }
94
+ public virtual IEnumerable < ConstructorInfo > DeclaredConstructors => _type . GetConstructors ( DeclaredOnlyLookup ) ;
103
95
104
- public virtual IEnumerable < EventInfo > DeclaredEvents
105
- {
106
- get
107
- {
108
- return _type . GetEvents ( DeclaredOnlyLookup ) ;
109
- }
110
- }
96
+ public virtual IEnumerable < EventInfo > DeclaredEvents => _type . GetEvents ( DeclaredOnlyLookup ) ;
111
97
112
- public virtual IEnumerable < FieldInfo > DeclaredFields
113
- {
114
- get
115
- {
116
- return _type . GetFields ( DeclaredOnlyLookup ) ;
117
- }
118
- }
98
+ public virtual IEnumerable < FieldInfo > DeclaredFields => _type . GetFields ( DeclaredOnlyLookup ) ;
119
99
120
- public virtual IEnumerable < MemberInfo > DeclaredMembers
121
- {
122
- get
123
- {
124
- return _type . GetMembers ( DeclaredOnlyLookup ) ;
125
- }
126
- }
100
+ public virtual IEnumerable < MemberInfo > DeclaredMembers => _type . GetMembers ( DeclaredOnlyLookup ) ;
127
101
128
- public virtual IEnumerable < MethodInfo > DeclaredMethods
129
- {
130
- get
131
- {
132
- return _type . GetMethods ( DeclaredOnlyLookup ) ;
133
- }
134
- }
135
- public virtual IEnumerable < System . Reflection . TypeInfo > DeclaredNestedTypes
102
+ public virtual IEnumerable < MethodInfo > DeclaredMethods => _type . GetMethods ( DeclaredOnlyLookup ) ;
103
+
104
+ public virtual IEnumerable < TypeInfo > DeclaredNestedTypes
136
105
{
137
106
get
138
107
{
@@ -143,25 +112,12 @@ public virtual IEnumerable<System.Reflection.TypeInfo> DeclaredNestedTypes
143
112
}
144
113
}
145
114
146
- public virtual IEnumerable < PropertyInfo > DeclaredProperties
147
- {
148
- get
149
- {
150
- return _type . GetProperties ( DeclaredOnlyLookup ) ;
151
- }
152
- }
153
-
115
+ public virtual IEnumerable < PropertyInfo > DeclaredProperties => _type . GetProperties ( DeclaredOnlyLookup ) ;
154
116
155
- public virtual IEnumerable < Type > ImplementedInterfaces
156
- {
157
- get
158
- {
159
- return _type . GetInterfaces ( ) ;
160
- }
161
- }
162
117
118
+ public virtual IEnumerable < Type > ImplementedInterfaces => _type . GetInterfaces ( ) ;
163
119
164
- #endregion
120
+ #endregion
165
121
166
122
public override int GetHashCode ( )
167
123
{
@@ -183,13 +139,38 @@ public override bool Equals(object obj)
183
139
return left ? . GetHashCode ( ) != right ? . GetHashCode ( ) ;
184
140
}
185
141
142
+ public Type GetGenericTypeDefinition ( )
143
+ {
144
+ return _type . GetGenericTypeDefinition ( ) ;
145
+ }
186
146
}
147
+ }
187
148
#endif
188
149
150
+ namespace Unity
151
+ {
152
+ using System ;
153
+ using System . Reflection ;
154
+
189
155
190
- internal static class IntrospectionExtensions
156
+ internal static class Compatibility
191
157
{
158
+ #if NETSTANDARD1_0
159
+ public static System . Reflection . ConstructorInfo [ ] GetConstructors ( this System . Type type )
160
+ {
161
+ var ctors = type . GetTypeInfo ( ) . DeclaredConstructors ;
162
+ return ctors is ConstructorInfo [ ] array ? array : ctors . ToArray ( ) ;
163
+ }
164
+ #endif
165
+
192
166
#if NET40
167
+ public static Attribute GetCustomAttribute ( this ParameterInfo parameter , Type type )
168
+ {
169
+ return parameter . GetCustomAttributes ( false )
170
+ . OfType < DependencyResolutionAttribute > ( )
171
+ . FirstOrDefault ( ) ;
172
+ }
173
+
193
174
public static TypeInfo GetTypeInfo ( this Type type )
194
175
{
195
176
if ( type == null )
0 commit comments