有逆运算的类型吗?

编程入门 行业动态 更新时间:2024-10-23 16:29:22
本文介绍了有逆运算的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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:

  • StackOverflow:如何使用反射来调用泛型方法?
  • StackOverflow:最好的方法是什么从其名称实例化泛型?

更多推荐

有逆运算的类型吗?

本文发布于:2023-10-14 22:25:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:逆运算   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!