使用PrivateObject.Invoke调用静态转换函数不能在C#中编译 [英] Using PrivateObject.Invoke to call a static conversion function do not compile in C#
本文介绍了使用PrivateObject.Invoke调用静态转换函数不能在C#中编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个测试方法,我在其中调用一个私有函数,该函数将一种转换为另一种.
I have a test method where I call an private function that converts a kind of to another kind.
此静态函数具有以下签名:
This static function have the following signature:
private static Destiny[] Array2Array<Origin,Destiny> (Origin[] OriginVector)
由于它是私有函数,因此测试仪会给出一个错误消息,表明它无法访问它.所以我到了这一点:
Since it's a private function, the tester give an error saying it cannot access it. So I got to this point:
Origin[] OriginVector = null; // TODO: Initialize to an appropriate value
Destiny[] expected = null; // TODO: Initialize to an appropriate value
Destiny[] actual;
var dummy = new ConversionClass();
var po = new PrivateObject( dummy, new PrivateType(typeof(ConversionClass)));
var acessor = new ConversionClassAcessor(po);
actual = po.Invoke("Array2Array",
new [] { typeof(Origin[]), typeof(Destiny[]) },
new object[] { OriginVector } );
最后一行引发编译器错误,并显示消息无法将类型对象转换为Destiny []".我在做什么错了?
That last line throws an compiler error with the message "cannot convert type object to Destiny[]". What I'm doing wrong?
推荐答案
答案很简单. :D
actual = (Destiny[]) po.Invoke("Array2Array",
new [] { typeof(Origin[]), typeof(Destiny[]) },
new object[] { OriginVector } );
这篇关于使用PrivateObject.Invoke调用静态转换函数不能在C#中编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文