-
Notifications
You must be signed in to change notification settings - Fork 685
/
Copy pathAutoJoinedSubClassPart.cs
101 lines (78 loc) · 2.97 KB
/
AutoJoinedSubClassPart.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#if USE_NULLABLE
#nullable enable
#endif
using System;
using System.Collections.Generic;
using FluentNHibernate.Mapping;
using FluentNHibernate.Mapping.Providers;
using FluentNHibernate.MappingModel;
using FluentNHibernate.MappingModel.ClassBased;
namespace FluentNHibernate.Automapping;
#pragma warning disable 612,618
public class AutoJoinedSubClassPart<T> : JoinedSubClassPart<T>, IAutoClasslike
#pragma warning restore 612,618
{
readonly MappingProviderStore providers;
readonly IList<Member> mappedMembers = new List<Member>();
public AutoJoinedSubClassPart(string keyColumn)
: this(keyColumn, new MappingProviderStore())
{}
AutoJoinedSubClassPart(string keyColumn, MappingProviderStore providers)
: base(keyColumn, new AttributeStore(), providers)
{
this.providers = providers;
}
public object GetMapping()
{
return ((ISubclassMappingProvider)this).GetSubclassMapping();
}
void IAutoClasslike.DiscriminateSubClassesOnColumn(string column)
{
}
void IAutoClasslike.AlterModel(ClassMappingBase mapping)
{}
internal override void OnMemberMapped(Member member)
{
mappedMembers.Add(member);
}
public void JoinedSubClass<TSubclass>(string keyColumn, Action<AutoJoinedSubClassPart<TSubclass>> action)
{
var genericType = typeof(AutoJoinedSubClassPart<>).MakeGenericType(typeof(TSubclass));
var joinedclass = (AutoJoinedSubClassPart<TSubclass>)Activator.CreateInstance(genericType, keyColumn)!;
action(joinedclass);
providers.Subclasses[typeof(TSubclass)] = joinedclass;
}
public IAutoClasslike JoinedSubClass(Type type, string keyColumn)
{
var genericType = typeof(AutoJoinedSubClassPart<>).MakeGenericType(type);
var joinedclass = (ISubclassMappingProvider)Activator.CreateInstance(genericType, keyColumn)!;
providers.Subclasses[type] = joinedclass;
return (IAutoClasslike)joinedclass;
}
public void SubClass<TSubclass>(string discriminatorValue, Action<AutoSubClassPart<TSubclass>> action)
{
var genericType = typeof(AutoSubClassPart<>).MakeGenericType(typeof(TSubclass));
var subclass = (AutoSubClassPart<TSubclass>)Activator.CreateInstance(genericType, discriminatorValue)!;
action(subclass);
providers.Subclasses[typeof(TSubclass)] = subclass;
}
public IAutoClasslike SubClass(Type type, string discriminatorValue)
{
var genericType = typeof(AutoSubClassPart<>).MakeGenericType(type);
var subclass = (ISubclassMappingProvider)Activator.CreateInstance(genericType, discriminatorValue)!;
providers.Subclasses[type] = subclass;
return (IAutoClasslike)subclass;
}
public ClassMapping? GetClassMapping()
{
return null;
}
public HibernateMapping? GetHibernateMapping()
{
return null;
}
public IEnumerable<Member> GetIgnoredProperties()
{
return mappedMembers;
}
}