CodeGo.net>如何从objectName创建通用T?

我创建了一个FetchData方法,该方法返回IList<object>,并使用objectname(string)作为参数(我们要返回List的对象的名称)。

Task<IList<object>> FetchData(string processGuiId,string objectname);

我正在从FetchData(string processGuiId,string objectname)调用Gateway方法以从源获取数据。

_gateway.ReadByQueryAsync<T>();

如何通过T方法从objectname获得ReadByQueryAsync

tttttt001 回答:CodeGo.net>如何从objectName创建通用T?

您不能“从objectName创建通用T”,但是可以从类型构造通用方法。

我认为您正在寻找MethodInfo.MakeGenericMethod用法,例如:

<template>
  <div class="container">
    <v-chip-group column active-class="primary--text">
      <v-chip
        v-for="tag in tags"
        :key="tag"
        class="ma-2"
        outlined
        x-small
        color="blue"
        text-color="blue"
      >
        {{ tag }}
      </v-chip>
    </v-chip-group>
  </div>
</template>

<script>
export default {
  name: 'Tags',props: {
    tags: {
      type: Array,default: () => ['Empty'],},}
</script>

然后致电,例如:

// somehow get fully qualified name from objectName
vat type = Type.GetType("fully qualified name"); 
var mi = _gateway.GetType().GetMethod("ReadByQueryAsync").MakeGenericMethod(type);

或使用expression trees构建lambda并将其缓存。

mi.Invoke(_gateway,null) 的示例:

Enumerable.First()
本文链接:https://www.f2er.com/2302200.html

大家都在问