Skip to content

Commit ab42cdc

Browse files
ngbrownfredericDelaporte
authored andcommitted
NH-4020 - Use .netstandard compatible CreateTypeInfo()
TypeBuilder.CreateType() is now TypeBuilder.CreateTypeInfo() Switched cached System.Type to System.Reflection.TypeInfo
1 parent e49268c commit ab42cdc

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

src/NHibernate.Test/NHSpecificTest/NH3954/ProxyCacheFixture.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public void SetUp()
2424

2525
_internalCache = (ConcurrentDictionary<ProxyCacheEntry, System.Type>)InternalCacheField.GetValue(null);
2626

27-
_cache.StoreProxyType(typeof(Entity1FakeProxy), typeof(Entity1));
28-
_cache.StoreProxyType(typeof(Entity2FakeProxy), typeof(Entity2), typeof(INHibernateProxy));
29-
_cache.StoreProxyType(typeof(Entity3FakeProxy), typeof(Entity3));
30-
_cache.StoreProxyType(typeof(Entity4FakeProxy), typeof(Entity4), typeof(IProxy));
31-
_cache.StoreProxyType(typeof(Entity5FakeProxy), typeof(Entity5), typeof(INHibernateProxy), typeof(IProxy));
27+
_cache.StoreProxyType(typeof(Entity1FakeProxy).GetTypeInfo(), typeof(Entity1));
28+
_cache.StoreProxyType(typeof(Entity2FakeProxy).GetTypeInfo(), typeof(Entity2), typeof(INHibernateProxy));
29+
_cache.StoreProxyType(typeof(Entity3FakeProxy).GetTypeInfo(), typeof(Entity3));
30+
_cache.StoreProxyType(typeof(Entity4FakeProxy).GetTypeInfo(), typeof(Entity4), typeof(IProxy));
31+
_cache.StoreProxyType(typeof(Entity5FakeProxy).GetTypeInfo(), typeof(Entity5), typeof(INHibernateProxy), typeof(IProxy));
3232

3333
// Artificially inject other entries with same hashcodes
3434
_hashCode1 = new ProxyCacheEntry(typeof(Entity1), null).GetHashCode();
@@ -148,7 +148,7 @@ public void ProxyCacheNone()
148148
// Beware not testing the lookup failure of any combination, even tweaked, actually added in cache.
149149
// (Otherwise the test may starts failing unexpectedly sometimes, as the original bug ...)
150150
// This one was not added in anyway.
151-
System.Type result;
151+
TypeInfo result;
152152
Assert.IsFalse(_cache.TryGetProxyType(typeof(Entity2), new[] { typeof(IProxy) }, out result));
153153
}
154154
}

src/NHibernate/Proxy/DynamicProxy/IProxyCache.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
#endregion
88

99
using System;
10+
using System.Reflection;
1011

1112
namespace NHibernate.Proxy.DynamicProxy
1213
{
1314
public interface IProxyCache
1415
{
1516
bool Contains(System.Type baseType, params System.Type[] baseInterfaces);
16-
System.Type GetProxyType(System.Type baseType, params System.Type[] baseInterfaces);
17+
TypeInfo GetProxyType(System.Type baseType, params System.Type[] baseInterfaces);
1718

18-
bool TryGetProxyType(System.Type baseType, System.Type[] baseInterfaces, out System.Type proxyType);
19+
bool TryGetProxyType(System.Type baseType, System.Type[] baseInterfaces, out TypeInfo proxyType);
1920

20-
void StoreProxyType(System.Type result, System.Type baseType, params System.Type[] baseInterfaces);
21+
void StoreProxyType(TypeInfo result, System.Type baseType, params System.Type[] baseInterfaces);
2122
}
2223
}

src/NHibernate/Proxy/DynamicProxy/ProxyCache.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
#endregion
88

99
using System.Collections.Concurrent;
10+
using System.Reflection;
1011

1112
namespace NHibernate.Proxy.DynamicProxy
1213
{
1314
public class ProxyCache : IProxyCache
1415
{
15-
private static readonly ConcurrentDictionary<ProxyCacheEntry, System.Type> cache = new ConcurrentDictionary<ProxyCacheEntry, System.Type>();
16+
private static readonly ConcurrentDictionary<ProxyCacheEntry, TypeInfo> cache = new ConcurrentDictionary<ProxyCacheEntry, TypeInfo>();
1617

1718
#region IProxyCache Members
1819

@@ -27,13 +28,13 @@ public bool Contains(System.Type baseType, params System.Type[] baseInterfaces)
2728
return cache.ContainsKey(entry);
2829
}
2930

30-
public System.Type GetProxyType(System.Type baseType, params System.Type[] baseInterfaces)
31+
public TypeInfo GetProxyType(System.Type baseType, params System.Type[] baseInterfaces)
3132
{
3233
var entry = new ProxyCacheEntry(baseType, baseInterfaces);
3334
return cache[entry];
3435
}
3536

36-
public bool TryGetProxyType(System.Type baseType, System.Type[] baseInterfaces, out System.Type proxyType)
37+
public bool TryGetProxyType(System.Type baseType, System.Type[] baseInterfaces, out TypeInfo proxyType)
3738
{
3839
proxyType = null;
3940

@@ -44,7 +45,7 @@ public bool TryGetProxyType(System.Type baseType, System.Type[] baseInterfaces,
4445
return cache.TryGetValue(entry, out proxyType);
4546
}
4647

47-
public void StoreProxyType(System.Type result, System.Type baseType, params System.Type[] baseInterfaces)
48+
public void StoreProxyType(TypeInfo result, System.Type baseType, params System.Type[] baseInterfaces)
4849
{
4950
var entry = new ProxyCacheEntry(baseType, baseInterfaces);
5051
cache[entry] = result;

src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,29 @@ public System.Type CreateProxyType(System.Type baseType, params System.Type[] in
6868
{
6969
System.Type[] baseInterfaces = ReferenceEquals(null, interfaces) ? new System.Type[0] : interfaces.Where(t => t != null).ToArray();
7070

71-
System.Type proxyType;
71+
TypeInfo proxyTypeInfo;
7272

7373
// Reuse the previous results, if possible, Fast path without locking.
74-
if (Cache.TryGetProxyType(baseType, baseInterfaces, out proxyType))
75-
return proxyType;
74+
if (Cache.TryGetProxyType(baseType, baseInterfaces, out proxyTypeInfo))
75+
return proxyTypeInfo;
7676

7777
lock (Cache)
7878
{
7979
// Recheck in case we got interrupted.
80-
if (!Cache.TryGetProxyType(baseType, baseInterfaces, out proxyType))
80+
if (!Cache.TryGetProxyType(baseType, baseInterfaces, out proxyTypeInfo))
8181
{
82-
proxyType = CreateUncachedProxyType(baseType, baseInterfaces);
82+
proxyTypeInfo = CreateUncachedProxyType(baseType, baseInterfaces);
8383

8484
// Cache the proxy type
85-
if (proxyType != null && Cache != null)
86-
Cache.StoreProxyType(proxyType, baseType, baseInterfaces);
85+
if (proxyTypeInfo != null && Cache != null)
86+
Cache.StoreProxyType(proxyTypeInfo, baseType, baseInterfaces);
8787
}
8888

89-
return proxyType;
89+
return proxyTypeInfo;
9090
}
9191
}
9292

93-
private System.Type CreateUncachedProxyType(System.Type baseType, System.Type[] baseInterfaces)
93+
private TypeInfo CreateUncachedProxyType(System.Type baseType, System.Type[] baseInterfaces)
9494
{
9595
AppDomain currentDomain = AppDomain.CurrentDomain;
9696
string typeName = string.Format("{0}Proxy", baseType.Name);
@@ -145,7 +145,7 @@ private System.Type CreateUncachedProxyType(System.Type baseType, System.Type[]
145145

146146
// Make the proxy serializable
147147
AddSerializationSupport(baseType, baseInterfaces, typeBuilder, interceptorField, defaultConstructor);
148-
System.Type proxyType = typeBuilder.CreateType();
148+
TypeInfo proxyType = typeBuilder.CreateTypeInfo();
149149

150150
ProxyAssemblyBuilder.Save(assemblyBuilder);
151151
return proxyType;

0 commit comments

Comments
 (0)