我知道如何通过反射创建一些对象并传递一些参数。
Dim assembly As System.Reflection.Assembly
Dim control As Object
assembly = System.Reflection.Assembly.Load("WpfControlLibrary1")
control = assembly.CreateInstance("WpfControlLibrary1.Main")
control.Maximize("true")
我的问题是是否有一种方法可以将信息从“控件”获取到该“控件”的“所有者”。
所以我想应该是在所有者和创建的程序集之间进行双向交互的某种方式。
例如,在某些计时器中,我想定期获取“控件”的状态。
foreach(...)
{
var state = control.GetState(); // ????? Is it possible ?
Sleep(10000);
}
这里我们可以看到如何传递参数
所以我需要的是取回一些返回的对象。
提前感谢您在编程方面为我的兄弟姐妹提供任何有用的线索!
I know how to create some object by reflection and pass some arguments.
Dim assembly As System.Reflection.Assembly
Dim control As Object
assembly = System.Reflection.Assembly.Load("WpfControlLibrary1")
control = assembly.CreateInstance("WpfControlLibrary1.Main")
control.Maximize("true")
My question is if there is an approach to get info from "the control" into "the owner" of that "control".
So I guess should be some way to have bidirectional interaction between the owner and created assembly.
For example within some Timer I want get the states of the "control" periodically.
foreach(...)
{
var state = control.GetState(); // ????? Is it possible ?
Sleep(10000);
}
Here we can see how to pass the parameters
So what I need is to get back some returned object up.
Thank you in advance for any useful clue my brothers and sisters in programming!
发布评论
评论(1)
要调用在另一个程序集中的类上定义的方法,您需要如下所示:
这将调用程序集
OtherAssembly
的类OtherAssemblyClass
的方法SetFullName
> 在对象control
上,使用参数"FirstName"
和"LastNameski"
这将调用名为
GetFullName
的方法> 同样的对象,它不接受任何参数(因此调用中最后一个null
)并返回一个字符串。这将打印出
“System.String”
这将打印出
“FirstName LastNameski”
。在示例中,另一个程序集包含此类:
To invoke method defined on classes in another assembly, you need something like this:
This will invoke the method
SetFullName
of the classOtherAssemblyClass
of the assemblyOtherAssembly
on the objectcontrol
, using the parameters"FirstName"
and"LastNameski"
This will invoke a method called
GetFullName
on that same object, which accepts no parameters (hence the lastnull
in the call) and returns a string.This will print out
"System.String"
This will print out
"FirstName LastNameski"
.in the example, the other assembly contains this class: