-
Notifications
You must be signed in to change notification settings - Fork 934
/
Copy pathIJoinedSubclassMapper.cs
63 lines (57 loc) · 2.41 KB
/
IJoinedSubclassMapper.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 NHibernate.Mapping.ByCode.Impl;
using NHibernate.Mapping.ByCode.Impl.CustomizersImpl;
using NHibernate.Util;
namespace NHibernate.Mapping.ByCode
{
public interface IJoinedSubclassAttributesMapper : IEntityAttributesMapper, IEntitySqlsMapper
{
void Table(string tableName);
void Catalog(string catalogName);
void Schema(string schemaName);
void Key(Action<IKeyMapper> keyMapping);
void Extends(System.Type baseType);
void SchemaAction(SchemaAction action);
void Filter(string filterName, Action<IFilterMapper> filterMapping);
void Abstract(bool isAbstract);
}
public interface IJoinedSubclassMapper : IJoinedSubclassAttributesMapper, IPropertyContainerMapper {}
public interface IJoinedSubclassAttributesMapper<TEntity> : IEntityAttributesMapper, IEntitySqlsMapper where TEntity : class
{
void Abstract(bool isAbstract);
void Extends(System.Type baseType);
void Table(string tableName);
void Catalog(string catalogName);
void Schema(string schemaName);
void Key(Action<IKeyMapper<TEntity>> keyMapping);
void SchemaAction(SchemaAction action);
void Filter(string filterName, Action<IFilterMapper> filterMapping);
}
public interface IJoinedSubclassMapper<TEntity> : IJoinedSubclassAttributesMapper<TEntity>, IPropertyContainerMapper<TEntity> where TEntity : class {}
public static class JoinedSubclassAttributesMapperExtensions
{
//6.0 TODO: Merge to IJoinedSubclassAttributesMapper<TEntity>
public static void Extends<TEntity>(this IJoinedSubclassAttributesMapper<TEntity> mapper, string entityOrClassName)
where TEntity : class
{
switch (mapper)
{
case JoinedSubclassCustomizer<TEntity> jsc:
jsc.Extends(entityOrClassName);
break;
case PropertyContainerCustomizer<TEntity> pcc:
pcc.CustomizersHolder.AddCustomizer(
typeof(TEntity),
(IJoinedSubclassAttributesMapper m) => m.Extends(entityOrClassName));
break;
default:
throw new ArgumentException($@"{mapper.GetType()} requires to extend {typeof(JoinedSubclassCustomizer<TEntity>).FullName} or {typeof(PropertyContainerCustomizer<TEntity>).FullName} to support Extends(entityOrClassName).");
}
}
//6.0 TODO: Merge to IJoinedSubclassAttributesMapper
public static void Extends(this IJoinedSubclassAttributesMapper mapper, string entityOrClassName)
{
ReflectHelper.CastOrThrow<JoinedSubclassMapper>(mapper, "Extends(entityOrClassName)").Extends(entityOrClassName);
}
}
}