nhibernate GetType
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nhibernate GetType,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2020字,纯文字阅读大概需要3分钟。
内容图文
![nhibernate GetType](/upload/InfoBanner/zyjiaocheng/1253/764e251afee441f19f52e65ef81927dd.jpg)
本原理 /* This code assumes an IEntity interface that identifies your persistent types. */ /// <summary> /// This static class provides common extension methods for <see cref="IEntity"/> types. /// </summary> public static class EntityExtensions { /// <summary> /// Gets the real, underlying Entity-type - as opposed to the standard GetType() method, /// this method takes into account the possibility that the object may in fact be an /// NHibernate Proxy object, and not a real object. This method will return the real /// Entity-type, doing a full initialization if necessary. /// </summary> public static Type GetEntityType(this IEntity entity ) { if(entity is INHibernateProxy) { var lazyInitialiser = ((INHibernateProxy)entity).HibernateLazyInitializer; var type = lazyInitialiser.PersistentClass; if( type.IsAbstract || type.GetNestedTypes().Length >0 ) return Unproxy ( entity ).GetType (); else// we don‘t need to "unbox" the Proxy-object to get the typereturn lazyInitialiser.PersistentClass ; } return entity.GetType (); } ///<summary>/// Based on the real, underlying Entity-type, this method returns true if the specified /// type matches (or is assignable from) the specified Type. ///</summary>publicstaticbool Is < TEntity >( this IEntity entity ) where TEntity : class , IEntity { var entityType = entity.GetEntityType (); var type = typeof ( TEntity ); return entityType == type || type.IsAssignableFrom ( entityType ); } ///<summary>/// In some cases, you may need the actual object, not just the type - for example, if /// you‘re going to cast to a type deeper in the hierarchy, you may need to Unproxy /// the object first. ///</summary>publicstatic TEntity Unproxy < TEntity >( this TEntity entity ) where TEntity : class , IEntity { return entity is INHibernateProxy ? (TEntity)Service.Session.GetSessionImplementation ().PersistenceContext.Unproxy(entity ):entity ; } }
原文:http://www.cnblogs.com/kexb/p/6041123.html
内容总结
以上是互联网集市为您收集整理的nhibernate GetType全部内容,希望文章能够帮你解决nhibernate GetType所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。
来源:【匿名】