有逆运算的类型吗? [英] Is there a typeof inverse operation?

查看:25
本文介绍了有逆运算的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了类型,但这与我正在寻找的类不同.

I get the Type but that's not the same as the Class which is what I'm looking for.

有typeof的逆运算吗?

Is there an inverse operation of typeof?

我需要该类才能使用通用存储库:

I need the class in order to use a generic repository:

GenericRepository<BaseEntity> repository = new GenericRepository<BaseEntity>(new AzureBrightData());

我首先编写了所有实体类都从它派生的 BaseEntity,但问题是存储库需要知道要搜索哪个表.

I started by writing BaseEntity from which all entity class descend, but the problem is that the repository needs to know which table to search for.

例如,如果我们有一个分区键和行键组合对 (1,1),这不允许我或存储库知道从哪个表获取注册表.这还不够,这就是为什么我认为我需要这张桌子.

For example, if we have a partition key and row key combination pair of (1,1) this doesn't allow me or the repository to know from which table to get the registry. It's not enough and that's why I believe I need the table.

推荐答案

我的回答基于您在评论中提供的说明:

I'll base my answer on the clarification you provided in a comment:

我误解了这里每个人所说的,或者至少我没有说清楚.我想像平时一样上课.例如,我必须像这样传递类:public void methodName() 其中 T 是类.

I misunderstood what everyone said here or at least I did not make myself clear. I want to get the class as I would use it normally. For example, I have to pass the class like this: public void methodName<T>() where T is the class.

简短回答:不,你不能,因为泛型类型是在编译时解析的.

Short answer: No, you can't, because generic types are resolved at compile time.

长答案:是的,你可以,但你需要使用反射.这样做的方法如下:

Long answer: Yes, you can, but you need to use reflection. Here's how you do that:

这篇关于有逆运算的类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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