请问,如果动态调用一个dll文件,那么它里面的ref参数应如何传递呢。

ydx 2005-02-28 11:39:54
谢谢
...全文
333 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ydx 2005-03-07
  • 打赏
  • 举报
回复
大家在测测传dataset的参数,是不是ds里并没有数据。
ydx 2005-03-06
  • 打赏
  • 举报
回复
对,是可能编译,可是我传的是dataset的参数。为什么传回来后没有内容呢,在msdn中也说不用加特殊的属性的。
另外,如果在调用一个方法时用ref 传递ds,这样是不是可以节省一些内存的占用。
sutalon 2005-03-05
  • 打赏
  • 举报
回复
你可以看看我写的测试代码:

//被测试的方法(加了 ref):
class AB
{
public void Add(ref int result,int y)
{
result += y;
result *= result;
}
}

//测试代码
static void Main(string[] args)
{
//反射生成 类ConsoleAppl.AB 的一个实例
object obj = Activator.CreateInstance(typeof(ConsoleAppl.AB));
//得到 类ConsoleAppl.AB 的类型
Type type = obj.GetType();

//得到 类ConsoleAppl.AB 的 “Add” 方法
MethodInfo method = type.GetMethod("Add");

//构建“Add”方法的参数
object [] parameters =new object[]{1,2};

//激发本方法
method.Invoke(obj,parameters);

//打印出结果,为 9 ,正确
Console.WriteLine(parameters[0].ToString());

Console.Read();
}
sutalon 2005-03-05
  • 打赏
  • 举报
回复
恩,我测试过,好像不用加 ref 的修饰符,可以编译通过,可以执行,结果也对阿
ydx 2005-03-05
  • 打赏
  • 举报
回复
不行,编译不过去。
FJGoodGood 2005-03-05
  • 打赏
  • 举报
回复
应该跟平常的一样吧,加一个 ref :

GetAllCustomer.Invoke(obj,ref a, b, c, ...);
ydx 2005-03-05
  • 打赏
  • 举报
回复
没有人碰到过吗?
DataSet ds=new DataSet();
//InitializeFormMethond.GetCustomer (ref ds);
string fileName=@"\Smartcustomer.dll";
string filePath=Application.StartupPath+fileName;
string typeName="Smartcustomer.Customer";
ObjectHandle objHandle = Activator.CreateInstanceFrom(filePath,typeName);//strAssembly是程序集名称,strClass是类名
Object obj = objHandle.Unwrap();
Type type = obj.GetType();
object []parameters={ds};
MethodInfo GetAllCustomer= type.GetMethod("GetAllCustomer");//strOp方法名称
GetAllCustomer.Invoke(obj,parameters );
如果GetAllCustomer的参数是以ref 传递的,请问该如何写呢?
jiezhi 2005-02-28
  • 打赏
  • 举报
回复
动态加载dll
Asssemble.Load()

ref
获得实例后,
string str = "";
myObject.Method1(ref str);

具体参考msdn吧
ydx 2005-02-28
  • 打赏
  • 举报
回复
能在详细一点吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧