Skip to content

Commit 455e633

Browse files
Merge pull request #577 from kiyoaki/master
Move ReflectionExtensions namespace to HoloToolkit
2 parents 54734f5 + 182db4f commit 455e633

File tree

1 file changed

+151
-148
lines changed

1 file changed

+151
-148
lines changed
Lines changed: 151 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,202 +1,205 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
namespace HoloToolkit
5+
{
46
#if UNITY_METRO && !UNITY_EDITOR
57

6-
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Reflection;
10-
using System.Text;
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using System.Reflection;
12+
using System.Text;
1113

12-
public static class ReflectionExtensions
13-
{
14-
public static EventInfo GetEvent(this Type type, string eventName)
14+
public static class ReflectionExtensions
1515
{
16-
return type.GetRuntimeEvent(eventName);
17-
}
16+
public static EventInfo GetEvent(this Type type, string eventName)
17+
{
18+
return type.GetRuntimeEvent(eventName);
19+
}
1820

19-
public static MethodInfo GetMethod(this Type type, string methodName)
20-
{
21-
return GetMethod(type, methodName, (BindingFlags)0x0);
22-
}
21+
public static MethodInfo GetMethod(this Type type, string methodName)
22+
{
23+
return GetMethod(type, methodName, (BindingFlags)0x0);
24+
}
2325

24-
public static MethodInfo GetMethod(this Type type, string methodName, BindingFlags flags)
25-
{
26-
var result = type.GetTypeInfo().GetDeclaredMethod(methodName);
27-
if (((flags & BindingFlags.FlattenHierarchy) != 0) && result == null)
26+
public static MethodInfo GetMethod(this Type type, string methodName, BindingFlags flags)
2827
{
29-
var baseType = type.GetBaseType();
30-
if (baseType != null)
28+
var result = type.GetTypeInfo().GetDeclaredMethod(methodName);
29+
if (((flags & BindingFlags.FlattenHierarchy) != 0) && result == null)
3130
{
32-
return GetMethod(baseType, methodName, flags);
31+
var baseType = type.GetBaseType();
32+
if (baseType != null)
33+
{
34+
return GetMethod(baseType, methodName, flags);
35+
}
3336
}
34-
}
3537

36-
return result;
37-
}
38+
return result;
39+
}
3840

39-
public static MethodInfo GetMethod(this Type type, string methodName, BindingFlags bindingAttr, Object binder, Type[] parameters, Object[] modifiers)
40-
{
41-
var result = type.GetTypeInfo().GetDeclaredMethod(methodName);
42-
if (result == null)
41+
public static MethodInfo GetMethod(this Type type, string methodName, BindingFlags bindingAttr, Object binder, Type[] parameters, Object[] modifiers)
4342
{
44-
var baseType = type.GetBaseType();
45-
if (baseType != null)
43+
var result = type.GetTypeInfo().GetDeclaredMethod(methodName);
44+
if (result == null)
4645
{
47-
return GetMethod(baseType, methodName, bindingAttr, binder, parameters, modifiers);
46+
var baseType = type.GetBaseType();
47+
if (baseType != null)
48+
{
49+
return GetMethod(baseType, methodName, bindingAttr, binder, parameters, modifiers);
50+
}
4851
}
49-
}
5052

51-
return result;
52-
}
53+
return result;
54+
}
5355

54-
public static MethodInfo GetMethod(this Type type, string methodName, Type[] parameters)
55-
{
56-
return GetMethods(type).Where(m => m.Name == methodName).FirstOrDefault(
57-
m =>
58-
{
59-
var types = m.GetParameters().Select(p => p.ParameterType).ToArray();
60-
if (types.Length == parameters.Length)
56+
public static MethodInfo GetMethod(this Type type, string methodName, Type[] parameters)
57+
{
58+
return GetMethods(type).Where(m => m.Name == methodName).FirstOrDefault(
59+
m =>
6160
{
62-
for (int idx = 0; idx < types.Length; idx++)
61+
var types = m.GetParameters().Select(p => p.ParameterType).ToArray();
62+
if (types.Length == parameters.Length)
6363
{
64-
if (types[idx] != parameters[idx])
64+
for (int idx = 0; idx < types.Length; idx++)
6565
{
66-
return false;
66+
if (types[idx] != parameters[idx])
67+
{
68+
return false;
69+
}
6770
}
68-
}
6971

70-
return true;
71-
}
72-
else
73-
{
74-
return false;
72+
return true;
73+
}
74+
else
75+
{
76+
return false;
77+
}
7578
}
76-
}
77-
);
78-
}
79+
);
80+
}
7981

80-
public static IEnumerable<MethodInfo> GetMethods(this Type type)
81-
{
82-
return GetMethods(type, (BindingFlags)0x0);
83-
}
82+
public static IEnumerable<MethodInfo> GetMethods(this Type type)
83+
{
84+
return GetMethods(type, (BindingFlags)0x0);
85+
}
8486

85-
public static IEnumerable<MethodInfo> GetMethods(this Type type, BindingFlags flags)
86-
{
87-
return type.GetTypeInfo().GetMethods(flags);
88-
}
87+
public static IEnumerable<MethodInfo> GetMethods(this Type type, BindingFlags flags)
88+
{
89+
return type.GetTypeInfo().GetMethods(flags);
90+
}
8991

90-
public static IEnumerable<MethodInfo> GetMethods(this TypeInfo type)
91-
{
92-
return GetMethods(type, (BindingFlags)0x0);
93-
}
92+
public static IEnumerable<MethodInfo> GetMethods(this TypeInfo type)
93+
{
94+
return GetMethods(type, (BindingFlags)0x0);
95+
}
9496

95-
public static IEnumerable<MethodInfo> GetMethods(this TypeInfo type, BindingFlags flags)
96-
{
97-
return type.DeclaredMethods;
98-
}
97+
public static IEnumerable<MethodInfo> GetMethods(this TypeInfo type, BindingFlags flags)
98+
{
99+
return type.DeclaredMethods;
100+
}
99101

100-
public static IEnumerable<FieldInfo> GetFields(this Type type)
101-
{
102-
return GetFields(type, (BindingFlags)0x0);
103-
}
102+
public static IEnumerable<FieldInfo> GetFields(this Type type)
103+
{
104+
return GetFields(type, (BindingFlags)0x0);
105+
}
104106

105-
public static IEnumerable<FieldInfo> GetFields(this Type type, BindingFlags flags)
106-
{
107-
return type.GetTypeInfo().DeclaredFields;
108-
}
107+
public static IEnumerable<FieldInfo> GetFields(this Type type, BindingFlags flags)
108+
{
109+
return type.GetTypeInfo().DeclaredFields;
110+
}
109111

110-
public static FieldInfo GetField(this Type type, string fieldName)
111-
{
112-
return type.GetRuntimeField(fieldName);
113-
}
112+
public static FieldInfo GetField(this Type type, string fieldName)
113+
{
114+
return type.GetRuntimeField(fieldName);
115+
}
114116

115-
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags flags)
116-
{
117-
return type.GetTypeInfo().DeclaredProperties;
118-
}
117+
public static IEnumerable<PropertyInfo> GetProperties(this Type type, BindingFlags flags)
118+
{
119+
return type.GetTypeInfo().DeclaredProperties;
120+
}
119121

120-
public static PropertyInfo GetProperty(this Type type, string propertyName)
121-
{
122-
return GetProperty(type, propertyName, (BindingFlags)0x0);
123-
}
122+
public static PropertyInfo GetProperty(this Type type, string propertyName)
123+
{
124+
return GetProperty(type, propertyName, (BindingFlags)0x0);
125+
}
124126

125-
public static PropertyInfo GetProperty(this Type type, string propertyName, BindingFlags flags)
126-
{
127-
return type.GetRuntimeProperty (propertyName);
128-
}
127+
public static PropertyInfo GetProperty(this Type type, string propertyName, BindingFlags flags)
128+
{
129+
return type.GetRuntimeProperty (propertyName);
130+
}
129131

130-
public static PropertyInfo GetProperty(this Type type, string propertyName, Type returnType)
131-
{
132-
return type.GetRuntimeProperty (propertyName);
133-
}
132+
public static PropertyInfo GetProperty(this Type type, string propertyName, Type returnType)
133+
{
134+
return type.GetRuntimeProperty (propertyName);
135+
}
134136

135-
public static IEnumerable<TypeInfo> GetTypes(this Assembly assembly)
136-
{
137-
return assembly.DefinedTypes;
138-
}
137+
public static IEnumerable<TypeInfo> GetTypes(this Assembly assembly)
138+
{
139+
return assembly.DefinedTypes;
140+
}
139141

140-
public static bool IsSubclassOf(this Type type, Type c)
141-
{
142-
return type.GetTypeInfo().IsSubclassOf(c);
143-
}
142+
public static bool IsSubclassOf(this Type type, Type c)
143+
{
144+
return type.GetTypeInfo().IsSubclassOf(c);
145+
}
144146

145-
public static bool IsAssignableFrom(this Type type, Type c)
146-
{
147-
return type.IsAssignableFrom(c.GetTypeInfo());
148-
}
147+
public static bool IsAssignableFrom(this Type type, Type c)
148+
{
149+
return type.IsAssignableFrom(c.GetTypeInfo());
150+
}
149151

150-
public static bool IsEnum(this Type type)
151-
{
152-
return type.GetTypeInfo().IsEnum;
153-
}
152+
public static bool IsEnum(this Type type)
153+
{
154+
return type.GetTypeInfo().IsEnum;
155+
}
154156

155-
public static bool IsValueType(this Type type)
156-
{
157-
return type.GetTypeInfo().IsValueType;
158-
}
157+
public static bool IsValueType(this Type type)
158+
{
159+
return type.GetTypeInfo().IsValueType;
160+
}
159161

160-
public static bool IsAssignableFrom(this Type type, TypeInfo typeInfo)
161-
{
162-
return type.GetTypeInfo().IsAssignableFrom(typeInfo);
163-
}
162+
public static bool IsAssignableFrom(this Type type, TypeInfo typeInfo)
163+
{
164+
return type.GetTypeInfo().IsAssignableFrom(typeInfo);
165+
}
164166

165-
public static object[] GetCustomAttributes(this Type type, bool inherit)
166-
{
167-
return type.GetTypeInfo().GetCustomAttributes(inherit).ToArray();
168-
}
167+
public static object[] GetCustomAttributes(this Type type, bool inherit)
168+
{
169+
return type.GetTypeInfo().GetCustomAttributes(inherit).ToArray();
170+
}
169171

170-
public static object[] GetCustomAttributes(this Type type, Type attributeType, bool inherit)
171-
{
172-
return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit).ToArray();
172+
public static object[] GetCustomAttributes(this Type type, Type attributeType, bool inherit)
173+
{
174+
return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit).ToArray();
175+
}
173176
}
174-
}
175177
#else
176178

177-
using System;
179+
using System;
178180

179-
public static class ReflectionExtensions
180-
{
181-
public static Type GetTypeInfo(this Type type)
181+
public static class ReflectionExtensions
182182
{
183-
return type;
184-
}
183+
public static Type GetTypeInfo(this Type type)
184+
{
185+
return type;
186+
}
185187

186-
public static Type AsType(this Type type)
187-
{
188-
return type;
189-
}
188+
public static Type AsType(this Type type)
189+
{
190+
return type;
191+
}
190192

191-
public static bool IsEnum(this Type type)
192-
{
193-
return type.IsEnum;
194-
}
193+
public static bool IsEnum(this Type type)
194+
{
195+
return type.IsEnum;
196+
}
195197

196-
public static bool IsValueType(this Type type)
197-
{
198-
return type.IsValueType;
198+
public static bool IsValueType(this Type type)
199+
{
200+
return type.IsValueType;
201+
}
199202
}
200-
}
201203

202-
#endif
204+
#endif
205+
}

0 commit comments

Comments
 (0)