How to add a method member to a class or object in run-time?

  • Thread starter Thread starter peter
  • Start date Start date
P

peter

In run-time,is there any approach to add or revise the
members,such as method or attribute ,of a class or object?
As for the object of class soapclient30 in MS soap
toolkit, after it executes the mssoapinit method,it will
have some additional methods which have been described in
WSDL file. For an example,if a Web service provides
an "divide" method,the WSDL filename is mycalculator.wsdl:

set soapclient = CreateObject("MSSOAP.SoapClient30")
soapclient.mssoapinit "mycalculator.wsdl", "", "", ""
soapclient.divide 10,5

that is,the soapclient object has the divide method.
how to add the "divide" method for SoapClient30 class
internally?
 
This won't work in C#, because object.method needs to be resolved at
compile-time, and the method doesn't exist. Try creating a method called
"Invoke" that takes a string argument specifying the name of the "method"
you want to run. The implementation is up to you (you could dynamically
generate code using Reflection.Emit, or just have custom code to interpret
any commands).

-mike
MVP
 
Thanks a lot,you are so kind.
Your solution is useful for me.But the class,
soapclient30 in MS soap toolkit30,is implemented the
function that I expect well and truly.Would you please
take some time to analysis the soapclient30 class?
I will appreciate an early reply.
 
Back
Top