You need to assign a valid function (hosted by some class in the dynamically loaded dll) to your delegate variable. If the functions are static methods on classes with the same name, this is straightforward:
public MyClass() {
this.MyFuncToCallFrmApp = ExternalClass.Function;
}
If the functions are instance methods of classes with the same name, just create an instance and do the same thing (also note that as long as the delegate is in scope, it will prevent the ExternalClass
instance from being garbage-collected - you may want to store the instance as a member variable to make that clearer):
public MyClass() {
this.MyFuncToCallFrmApp = new ExternalClass().Function;
}
If the dynamically-loaded classes have different names, you'll need to determine which one to call - in this example, I'm using a boolean member variable to decide whether or not to use a default assembly's class:
public MyClass() {
if (this.defaultAssembly) {
this.MyFuncToCallFrmApp = ExternalClass1.Function;
} else {
this.MyFuncToCallFrmApp = ExternalClass2.Function;
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…