关于使用泛型T及其基本继承限制 [英] About using generic T with limit its base inheritance

查看:106
本文介绍了关于使用泛型T及其基本继承限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这种情况下,我有时会停留在
在一个项目中,我使用LLBLGEN框架并从Repository< T>继承我的Repository类.储存库T的类别和适应性其中T:EntityBase
我这样做是因为要使用EntityCollectionFactory T必须是EntityBase
好吧,这是我的问题,我有我的Repository< T>没有限制类型的类,因为我可以使用任何其他实体框架,因此在某种情况下,我必须在linqmetadata中使用扩展方法(来自LLBLGEN lib.),并且该方法具有定义其中T:IEntityCore". 因为我的T不是IEntityCore,所以我不能使用此方法.

I 've stuck at sometimes for this situation
In a project i use LLBLGEN framework and inherit my Repository classes from Repository<T> class and defitiniton for Repository<T> where T : EntityBase
I 'm doing this because to use EntityCollectionFactory T must be EntityBase
Well here is my problem i have my Repository<T> class with no limited type because i can use any other entity frameworks, so in a case i must use a extension method in linqmetadata (from LLBLGEN lib.) and method has a definition "where T : IEntityCore" so i can 't use this method because of my T is not IEntityCore and i must not do it.

使用T并定义它是从任何接口继承的,有什么办法吗?或者我的想法是完全错误的?

Is there any way to do when using the T and define it s inherited from any interface or my idea is completely wrong ?

推荐答案

您的意思是重新定义第三方库的方法声明吗?不!

Do you mean redefine the method declaration of a third party library? No!

但是您可以编写一个实现该接口的类型,并使用该对象包装您的实体.

But you can write a type that implments that interface and wrap your entities with that object.


这篇关于关于使用泛型T及其基本继承限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆