简体   繁体   English

获取嵌套的委托类型引用。 从泛型类内部

[英]Get nested delegate type ref. from inside a generic class

I tried to retrieve the TYPE for "PreProcess" from DomainDB class using 我尝试使用以下方法从DomainDB类检索“ PreProcess”的类型

Type.GetType("DomainDBManager.DomainDB`1[System.String]+PreProcess") 

but this is returning null. 但这返回null。 Is there anyway to get the Public Field "PreProcess" using Type.GetType? 无论如何,有使用Type.GetType获取公共字段“ PreProcess”吗?

namespace DomainDBManager { public class DomainDB<T> { public Action<string> PreProcess; 命名空间DomainDBManager {公共类DomainDB <T> {public Action <string>预处理; } } }}

You're currently trying to get a type by name - PreProcess is a field of the DomainDB<T> type, so Type.GetType isn't going to work. 您目前正试图通过名字来获得一个类型 - PreProcess是的领域 DomainDB<T>类型,所以Type.GetType是行不通的。 You need to get the type first, and then get the field from that: 您需要先获取类型,然后从中获取字段:

Type type = Type.GetType("DomainDBManager.DomainDB`1[System.String]");
FieldInfo field = type.GetField("PreProcess");
Type fieldType = field.FieldType;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM