我正在用C#编写一个类库(API)。该类是非静态的并包含多个公共事件。是否有可能从一个单独的类中的静态方法触发这些事件? 例如...从静态类触发非静态类?
class nonStaticDLLCLASS
{
public event Event1;
public CallStaticMethod()
{
StaticTestClass.GoStaticMethod();
}
}
class StaticTestClass
{
public static GoStaticMethod()
{
// Here I want to fire Event1 in the nonStaticDLLCLASS
// I know the following line is not correct but can I do something like that?
(nonStaticDLLCLASS)StaticTestClass.ObjectThatCalledMe.Event1();
}
}
我知道你通常要访问它的方法,但在这种情况下,一个实例已经创建,只是没有通过类来创建非静态类的实例即试图访问它。
这使得一吨的感觉。我认为我的大脑不能正常工作! – PICyourBrain 2009-12-22 17:35:39