forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassThroughResultTransformer.cs
71 lines (60 loc) · 1.7 KB
/
PassThroughResultTransformer.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
using System;
using System.Collections;
using NHibernate.Util;
namespace NHibernate.Transform
{
[Serializable]
public class PassThroughResultTransformer : IResultTransformer, ITupleSubsetResultTransformer
{
internal static readonly PassThroughResultTransformer Instance = new PassThroughResultTransformer();
#region IResultTransformer Members
public object TransformTuple(object[] tuple, string[] aliases)
{
return tuple.Length == 1 ? tuple[0] : tuple;
}
public IList TransformList(IList collection)
{
return collection;
}
#endregion
public bool IsTransformedValueATupleElement(string[] aliases, int tupleLength)
{
return tupleLength == 1;
}
public bool[] IncludeInTransform(string[] aliases, int tupleLength)
{
bool[] includeInTransformedResult = new bool[tupleLength];
ArrayHelper.Fill(includeInTransformedResult, true);
return includeInTransformedResult;
}
internal IList UntransformToTuples(IList results, bool isSingleResult)
{
// untransform only if necessary; if transformed, do it in place;
if (isSingleResult)
{
for (int i = 0; i < results.Count; i++)
{
Object[] tuple = UntransformToTuple(results[i], isSingleResult);
results[i]= tuple;
}
}
return results;
}
internal object[] UntransformToTuple(object transformed, bool isSingleResult)
{
return isSingleResult ? new[] {transformed} : (object[]) transformed;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(obj, this))
return true;
if (obj == null)
return false;
return obj.GetType() == GetType();
}
public override int GetHashCode()
{
return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(Instance);
}
}
}