Skip to content

Commit be10835

Browse files
committed
NH-3807 - Took care of most of the GetTypeInfo() needs.
Added TypeReflectionExtensions for CoreClr use.
1 parent 8770454 commit be10835

File tree

91 files changed

+325
-208
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+325
-208
lines changed

src/NHibernate/AdoNet/OracleDataClientBatchingBatcher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Data;
44
using System.Data.Common;
5+
using System.Reflection;
56
using System.Text;
67
using NHibernate.AdoNet.Util;
78
using NHibernate.Exceptions;
@@ -162,4 +163,4 @@ public override int BatchSize
162163
set { _batchSize = value; }
163164
}
164165
}
165-
}
166+
}

src/NHibernate/Bytecode/AbstractBytecodeProvider.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using NHibernate.Properties;
34
using NHibernate.Util;
45

@@ -75,7 +76,7 @@ public virtual void SetProxyFactoryFactory(string typeName)
7576
throw new UnableToLoadProxyFactoryFactoryException(typeName, he);
7677
}
7778

78-
if (typeof(IProxyFactoryFactory).IsAssignableFrom(pffc) == false)
79+
if (typeof(IProxyFactoryFactory).GetTypeInfo().IsAssignableFrom(pffc) == false)
7980
{
8081
var he = new HibernateByteCodeException(pffc.FullName + " does not implement " + typeof(IProxyFactoryFactory).FullName);
8182
throw he;
@@ -116,4 +117,4 @@ public void SetCollectionTypeFactoryClass(System.Type type)
116117

117118
#endregion
118119
}
119-
}
120+
}

src/NHibernate/Bytecode/CodeDom/BytecodeProviderImpl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BytecodeProviderImpl : AbstractBytecodeProvider
1919

2020
public override IReflectionOptimizer GetReflectionOptimizer(System.Type clazz, IGetter[] getters, ISetter[] setters)
2121
{
22-
if (clazz.IsValueType)
22+
if (clazz.GetTypeInfo().IsValueType)
2323
{
2424
// Cannot create optimizer for value types - the setter method will not work.
2525
log.Info("Disabling reflection optimizer for value type " + clazz.FullName);
@@ -220,7 +220,7 @@ private string GenerateCode()
220220
{
221221
System.Type type = getters[i].ReturnType;
222222

223-
if (type.IsValueType)
223+
if (type.GetTypeInfo().IsValueType)
224224
{
225225
sb.AppendFormat(" t.{0} = values[{2}] == null ? new {1}() : ({1})values[{2}];\n", setter.PropertyName,
226226
type.FullName.Replace('+', '.'), i);
@@ -261,4 +261,4 @@ private string GenerateCode()
261261

262262
#endregion
263263
}
264-
}
264+
}

src/NHibernate/Bytecode/EmitUtil.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void EmitFastInt(ILGenerator il, int value)
6262

6363
public static void EmitBoxIfNeeded(ILGenerator il, System.Type type)
6464
{
65-
if (type.IsValueType)
65+
if (type.GetTypeInfo().IsValueType)
6666
{
6767
il.Emit(OpCodes.Box, type);
6868
}
@@ -103,7 +103,7 @@ static EmitUtil()
103103
public static void PreparePropertyForSet(ILGenerator il, System.Type propertyType)
104104
{
105105
// If this is a value type, we need to unbox it
106-
if (propertyType.IsValueType)
106+
if (propertyType.GetTypeInfo().IsValueType)
107107
{
108108
// if (object[i] == null), create a new instance
109109
Label notNullLabel = il.DefineLabel();
@@ -210,4 +210,4 @@ public static void EmitCreateDelegateInstance(ILGenerator il, System.Type delega
210210
il.Emit(OpCodes.Castclass, delegateType);
211211
}
212212
}
213-
}
213+
}

src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ReflectionOptimizer(System.Type mappedType, IGetter[] getters, ISetter[]
3636
{
3737
// save off references
3838
this.mappedType = mappedType;
39-
typeOfThis = mappedType.IsValueType ? mappedType.MakeByRefType() : mappedType;
39+
typeOfThis = mappedType.GetTypeInfo().IsValueType ? mappedType.MakeByRefType() : mappedType;
4040
//this.getters = getters;
4141
//this.setters = setters;
4242

@@ -54,7 +54,7 @@ public ReflectionOptimizer(System.Type mappedType, IGetter[] getters, ISetter[]
5454
/// </summary>
5555
protected virtual CreateInstanceInvoker CreateCreateInstanceMethod(System.Type type)
5656
{
57-
if (type.IsInterface || type.IsAbstract)
57+
if (type.GetTypeInfo().IsInterface || type.GetTypeInfo().IsAbstract)
5858
{
5959
return null;
6060
}
@@ -63,7 +63,7 @@ protected virtual CreateInstanceInvoker CreateCreateInstanceMethod(System.Type t
6363

6464
ILGenerator il = method.GetILGenerator();
6565

66-
if (type.IsValueType)
66+
if (type.GetTypeInfo().IsValueType)
6767
{
6868
LocalBuilder tmpLocal = il.DeclareLocal(type);
6969
il.Emit(OpCodes.Ldloca, tmpLocal);
@@ -99,7 +99,7 @@ protected virtual void ThrowExceptionForNoDefaultCtor(System.Type type)
9999

100100
protected DynamicMethod CreateDynamicMethod(System.Type returnType, System.Type[] argumentTypes)
101101
{
102-
System.Type owner = mappedType.IsInterface ? typeof (object) : mappedType;
102+
System.Type owner = mappedType.GetTypeInfo().IsInterface ? typeof (object) : mappedType;
103103
#pragma warning disable 618
104104
bool canSkipChecks = SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
105105
#pragma warning restore 618
@@ -108,7 +108,7 @@ protected DynamicMethod CreateDynamicMethod(System.Type returnType, System.Type[
108108

109109
private static void EmitCastToReference(ILGenerator il, System.Type type)
110110
{
111-
if (type.IsValueType)
111+
if (type.GetTypeInfo().IsValueType)
112112
{
113113
il.Emit(OpCodes.Unbox, type);
114114
}

src/NHibernate/Cfg/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public Configuration AddResources(IEnumerable<string> paths, Assembly assembly)
709709
/// </remarks>
710710
public Configuration AddClass(System.Type persistentClass)
711711
{
712-
return AddResource(persistentClass.FullName + ".hbm.xml", persistentClass.Assembly);
712+
return AddResource(persistentClass.FullName + ".hbm.xml", persistentClass.GetTypeInfo().Assembly);
713713
}
714714

715715
/// <summary>

src/NHibernate/Cfg/Environment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Configuration;
4+
using System.Linq;
45
using System.Reflection;
56

67
using NHibernate.Bytecode;
@@ -49,8 +50,7 @@ public static string Version
4950
{
5051
Assembly thisAssembly = Assembly.GetExecutingAssembly();
5152
var attrs =
52-
(AssemblyInformationalVersionAttribute[])
53-
thisAssembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
53+
thisAssembly.GetCustomAttributes<AssemblyInformationalVersionAttribute>().ToArray();
5454

5555
if (attrs != null && attrs.Length > 0)
5656
{

src/NHibernate/Cfg/XmlHbmBinding/CollectionBinder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Reflection;
45
using NHibernate.Mapping;
56
using NHibernate.Type;
67
using NHibernate.Util;
@@ -230,7 +231,7 @@ private void BindCollection(ICollectionPropertiesMapping collectionMapping, Mapp
230231
if (!isGeneric.HasValue && containingType != null)
231232
{
232233
collectionType = GetPropertyType(containingType, collectionMapping.Name, collectionMapping.Access);
233-
isGeneric = collectionType.IsGenericType;
234+
isGeneric = collectionType.GetTypeInfo().IsGenericType;
234235
}
235236

236237
model.IsGeneric = isGeneric.GetValueOrDefault();

src/NHibernate/Compat/CustomAttributeExtensions.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#if FEATURE_LEGACY_REFLECTION_API
1+
#if FEATURE_LEGACY_REFLECTION_API
22
// ReSharper disable once CheckNamespace
3+
4+
using System.Collections.Generic;
5+
36
namespace System.Reflection
47
{
58
/// <summary>
@@ -23,6 +26,17 @@ public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribu
2326
{
2427
return (T)Attribute.GetCustomAttribute(element, typeof(T));
2528
}
29+
30+
/// <summary>Retrieves a collection of custom attributes of a specified type that are applied to a specified assembly. </summary>
31+
/// <returns>A collection of the custom attributes that are applied to <paramref name="element" /> and that match <paramref name="T" />, or an empty collection if no such attributes exist. </returns>
32+
/// <param name="element">The assembly to inspect.</param>
33+
/// <typeparam name="T">The type of attribute to search for.</typeparam>
34+
/// <exception cref="T:System.ArgumentNullException">
35+
/// <paramref name="element" /> is null. </exception>
36+
public static IEnumerable<T> GetCustomAttributes<T>(this Assembly element) where T : Attribute
37+
{
38+
return (IEnumerable<T>) element.GetCustomAttributes(typeof(T), false);
39+
}
2640
}
2741
}
2842
#endif
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#if FEATURE_NETCORE_REFLECTION_API
2+
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Reflection;
6+
7+
namespace NHibernate
8+
{
9+
internal static class TypeReflectionExtensions
10+
{
11+
public static MethodInfo GetMethod(this System.Type type, string name, BindingFlags bindingAttr, object binder,
12+
System.Type[] types, ParameterModifier[] modifiers)
13+
{
14+
return type.GetMethods(bindingAttr)
15+
.FirstOrDefault(m => m.Name == name && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(types));
16+
}
17+
18+
public static PropertyInfo GetProperty(this System.Type type, string name, BindingFlags bindingAttr, System.Type returnType, object binder,
19+
System.Type[] types, ParameterModifier[] modifiers)
20+
{
21+
return type.GetProperties(bindingAttr)
22+
.FirstOrDefault(m => m.Name == name
23+
&& (returnType == null || m.PropertyType == returnType)
24+
&& (type == null || m.GetIndexParameters().Select(p => p.ParameterType).SequenceEqual(types)));
25+
}
26+
27+
public static ConstructorInfo GetConstructor(this System.Type type, BindingFlags bindingAttr, object binder,
28+
System.Type[] types, ParameterModifier[] modifiers)
29+
{
30+
return type.GetConstructors(bindingAttr)
31+
.FirstOrDefault(m => m.GetParameters().Select(p => p.ParameterType).SequenceEqual(types));
32+
}
33+
34+
public static ConstructorInfo GetConstructor(this System.Type type, BindingFlags bindingAttr, object binder,
35+
CallingConventions callingConventions, System.Type[] types, ParameterModifier[] modifiers)
36+
{
37+
return type.GetConstructors(bindingAttr)
38+
.FirstOrDefault(m => m.CallingConvention.HasFlag(callingConventions) && m.GetParameters().Select(p => p.ParameterType).SequenceEqual(types));
39+
}
40+
}
41+
}
42+
43+
#endif

0 commit comments

Comments
 (0)