forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjectHelpers.cs
32 lines (29 loc) · 878 Bytes
/
ObjectHelpers.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
namespace NHibernate.Util
{
/// <summary>
/// Various small helper methods.
/// </summary>
public static class ObjectHelpers
{
/// <summary>
/// Return an identifying string representation for the object, taking
/// NHibernate proxies into account. The returned string will be "null",
/// "classname@hashcode(hash)", or "entityname#identifier". If the object
/// is an uninitialized NHibernate proxy, take care not to initialize it.
/// </summary>
public static string IdentityToString(object obj)
{
if (obj == null)
{
return "null";
}
var proxy = obj as Proxy.INHibernateProxy;
if (null != proxy)
{
var init = proxy.HibernateLazyInitializer;
return StringHelper.Unqualify(init.EntityName) + "#" + init.Identifier;
}
return StringHelper.Unqualify(obj.GetType().FullName) + "@" + obj.GetHashCode() + "(hash)";
}
}
}