forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnwrapProxyPropertiesMetadata.cs
63 lines (53 loc) · 2 KB
/
UnwrapProxyPropertiesMetadata.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using Iesi.Collections.Generic;
using NHibernate.Util;
namespace NHibernate.Bytecode
{
/// <summary>
/// Information about all properties mapped as lazy="no-proxy" for an entity
/// </summary>
[Serializable]
public class UnwrapProxyPropertiesMetadata
{
public static UnwrapProxyPropertiesMetadata NonEnhanced(string entityName)
{
return new UnwrapProxyPropertiesMetadata(entityName, null);
}
public static UnwrapProxyPropertiesMetadata From(
string entityName,
IEnumerable<UnwrapProxyPropertyDescriptor> unwrapProxyPropertyDescriptors)
{
return new UnwrapProxyPropertiesMetadata(
entityName,
unwrapProxyPropertyDescriptors.ToDictionary(o => o.Name));
}
private readonly IDictionary<string, UnwrapProxyPropertyDescriptor> _unwrapProxyPropertyDescriptors;
public UnwrapProxyPropertiesMetadata(
string entityName,
IDictionary<string, UnwrapProxyPropertyDescriptor> unwrapProxyPropertyDescriptors)
{
EntityName = entityName;
_unwrapProxyPropertyDescriptors = unwrapProxyPropertyDescriptors;
HasUnwrapProxyProperties = unwrapProxyPropertyDescriptors?.Count > 0;
UnwrapProxyPropertyNames = HasUnwrapProxyProperties
? new ReadOnlySet<string>(new HashSet<string>(unwrapProxyPropertyDescriptors.Keys))
: CollectionHelper.EmptySet<string>();
}
public string EntityName { get; }
public bool HasUnwrapProxyProperties { get; }
public ISet<string> UnwrapProxyPropertyNames { get; }
public IEnumerable<UnwrapProxyPropertyDescriptor> UnwrapProxyPropertyDescriptors =>
_unwrapProxyPropertyDescriptors?.Values ?? Enumerable.Empty<UnwrapProxyPropertyDescriptor>();
public int GetUnwrapProxyPropertyIndex(string propertyName)
{
if (!_unwrapProxyPropertyDescriptors.TryGetValue(propertyName, out var descriptor))
{
throw new InvalidOperationException(
$"Property {propertyName} is not mapped as lazy=\"no-proxy\" on entity {EntityName}");
}
return descriptor.PropertyIndex;
}
}
}