-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathISubclassMapper.cs
61 lines (55 loc) · 2.16 KB
/
ISubclassMapper.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
using System;
using NHibernate.Mapping.ByCode.Impl;
using NHibernate.Mapping.ByCode.Impl.CustomizersImpl;
using NHibernate.Util;
namespace NHibernate.Mapping.ByCode
{
public interface ISubclassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMapper
{
void DiscriminatorValue(object value);
void Extends(System.Type baseType);
void Filter(string filterName, Action<IFilterMapper> filterMapping);
void Abstract(bool isAbstract);
}
public interface ISubclassMapper : ISubclassAttributesMapper, IPropertyContainerMapper
{
void Join(string splitGroupId, Action<IJoinMapper> splitMapping);
}
public interface ISubclassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class
{
void DiscriminatorValue(object value);
void Filter(string filterName, Action<IFilterMapper> filterMapping);
void Extends(System.Type baseType);
void Abstract(bool isAbstract);
}
public interface ISubclassMapper<TEntity> : ISubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class
{
void Join(string splitGroupId, Action<IJoinMapper<TEntity>> splitMapping);
}
public static class SubclassAttributesMapperExtensions
{
//6.0 TODO: Merge to ISubclassAttributesMapper<TEntity>
public static void Extends<TEntity>(this ISubclassAttributesMapper<TEntity> mapper, string entityOrClassName)
where TEntity : class
{
switch (mapper)
{
case SubclassCustomizer<TEntity> sc:
sc.Extends(entityOrClassName);
break;
case PropertyContainerCustomizer<TEntity> pcc:
pcc.CustomizersHolder.AddCustomizer(
typeof(TEntity),
(ISubclassMapper m) => m.Extends(entityOrClassName));
break;
default:
throw new ArgumentException($@"{mapper.GetType()} requires to extend {typeof(SubclassCustomizer<TEntity>).FullName} or {typeof(PropertyContainerCustomizer<TEntity>).FullName} to support Extends(entityOrClassName).");
}
}
//6.0 TODO: Merge to ISubclassAttributesMapper
public static void Extends(this ISubclassAttributesMapper mapper, string entityOrClassName)
{
ReflectHelper.CastOrThrow<SubclassMapper>(mapper, "Extends(entityOrClassName)").Extends(entityOrClassName);
}
}
}