forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponentTuplizerFactory.cs
40 lines (37 loc) · 1.21 KB
/
ComponentTuplizerFactory.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
using System;
using NHibernate.Util;
namespace NHibernate.Tuple.Component
{
/// <summary>
/// A registry allowing users to define the default <see cref="IComponentTuplizer"/> class to use per <see cref="EntityMode"/>;.
/// </summary>
[Serializable]
public class ComponentTuplizerFactory
{
static readonly System.Type[] ComponentTuplizerCtorSignature = { typeof(Mapping.Component) };
public IComponentTuplizer BuildDefaultComponentTuplizer(EntityMode entityMode, Mapping.Component component)
{
switch (entityMode)
{
case EntityMode.Poco:
return new PocoComponentTuplizer(component);
case EntityMode.Map:
return new DynamicMapComponentTuplizer(component);
default:
throw new ArgumentOutOfRangeException(nameof(entityMode), entityMode, null);
}
}
public IComponentTuplizer BuildComponentTuplizer(string tuplizerImpl, Mapping.Component component)
{
try
{
System.Type implClass = ReflectHelper.ClassForName(tuplizerImpl);
return (IComponentTuplizer)implClass.GetConstructor(ComponentTuplizerCtorSignature).Invoke(new object[] { component });
}
catch (Exception t)
{
throw new HibernateException("Could not build tuplizer [" + tuplizerImpl + "]", t);
}
}
}
}