如何使用反射动态键入方法的强制转换结果 [英] How do I type cast result of a method dynamically using reflection

查看:99
本文介绍了如何使用反射动态键入方法的强制转换结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不熟悉.net中的反思。我在dll中有一个方法(公共字典< int,collecthistory> CollectData()),其中 CollectedHistory 是同一个dll中的一个类。这个类有3个列表作为属性(字符串列表)。



我正在使用反射从另一个程序集调用此方法。并且此方法的结果已分配给VAR对象。



但是,我不清楚,我怎样才能将此方法的输出输入到Dictionary< ; int,collecthistory)> CollectData()方法存在)。



请告诉我,如何输出方法输出到正确的类型。

I am new to reflection in .net. I have a method in a dll (Public Dictionary<int,collectedhistory> CollectData()), where CollectedHistory is a class in the same dll. This class has 3 lists as properties (List of strings).

I am invoking this method from another assembly using reflection. And the result of this method has been assigned to a VAR object.

But, I am not clear, how can I type cast the output of this method in to Dictionary<int,collectedhistory)>CollectData() method exists).

Please advise me, how to type cast the method output to the proper type.

推荐答案

您将需要一个共享引用,例如接口或抽象类。两个程序集都应引用共享对象。



另一个选项是创建三个属性,返回每个 List< string> 。您可以在两个程序集中使用这些类型,因为您在 System.Collections
You will need a shared reference such as an interface or abstract class. both of your assemblies should reference the shared object.

The other option it to create three properties that return each of the List<string>. You can use these types in both of your assemblies because you have a shared resource in System.Collections

中有共享资源

这篇关于如何使用反射动态键入方法的强制转换结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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