-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathIUnionSubclassMapper.cs
57 lines (51 loc) · 2.08 KB
/
IUnionSubclassMapper.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
using System;
using NHibernate.Mapping.ByCode.Impl;
using NHibernate.Mapping.ByCode.Impl.CustomizersImpl;
using NHibernate.Util;
namespace NHibernate.Mapping.ByCode
{
public interface IUnionSubclassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMapper
{
void Table(string tableName);
void Catalog(string catalogName);
void Schema(string schemaName);
void Extends(System.Type baseType);
void Abstract(bool isAbstract);
}
public interface IUnionSubclassMapper : IUnionSubclassAttributesMapper, IPropertyContainerMapper {}
public interface IUnionSubclassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class
{
void Table(string tableName);
void Catalog(string catalogName);
void Schema(string schemaName);
void Extends(System.Type baseType);
void Abstract(bool isAbstract);
}
public interface IUnionSubclassMapper<TEntity> : IUnionSubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class {}
public static class UnionSubclassAttributesMapperExtensions
{
//6.0 TODO: Merge to IUnionSubclassAttributesMapper<TEntity>
public static void Extends<TEntity>(this IUnionSubclassAttributesMapper<TEntity> mapper, string entityOrClassName)
where TEntity : class
{
switch (mapper)
{
case UnionSubclassCustomizer<TEntity> usc:
usc.Extends(entityOrClassName);
break;
case PropertyContainerCustomizer<TEntity> pcc:
pcc.CustomizersHolder.AddCustomizer(
typeof(TEntity),
(IUnionSubclassAttributesMapper m) => m.Extends(entityOrClassName));
break;
default:
throw new ArgumentException($@"{mapper.GetType()} requires to extend {typeof(UnionSubclassCustomizer<TEntity>).FullName} or {typeof(PropertyContainerCustomizer<TEntity>).FullName} to support Extends(entityOrClassName).");
}
}
//6.0 TODO: Merge to IUnionSubclassAttributesMapper
public static void Extends(this IUnionSubclassAttributesMapper mapper, string entityOrClassName)
{
ReflectHelper.CastOrThrow<UnionSubclassMapper>(mapper, "Extends(entityOrClassName)").Extends(entityOrClassName);
}
}
}