Re: force cast of object to mytype...
- From: "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxxxxxxxx>
- Date: Sun, 17 Sep 2006 20:51:58 -0500
Eric,
First I would recommend this for your method:
Public Function Host_GetObject(ByVal FonctionName As String, ByVal ParamArray Parameters() As Object) As Object()
Allowing you to call the method like:
Host_GetObject("method1", a)
Host_GetObject("method2", a, b)
Host_GetObject("method3")
Host_GetObject("method1", a, b, c, d, e)
and even:
Dim args() As Object
Host_GetObject("method1", args)
Without needing to explicitly create an array of object. The ParamArray causes an object array to be implicitly created, unless you explicitly pass an array of object.
in the plugin, i get the array of object. good too.. but each object is typed with mainapp.StrPIsName all this is normal.
..NET is a managed strongly typed runtime. An value of MainApp.StrPIsName is distinct from a value of SomeAddin.StrPIsName. .NET does not look at the sequence of fields in a type to decide equivalence. instead it looks at the type's name, it's namespace, it's assembly, and even the assembly's version when deciding if a cast is allowed. Which means that
Private Structure StrPIsName
Friend PIName As String
Friend PIAssyName As String
End Structure
in two assemblies (MainApp & SomeAddin) are distinct types & cannot be cast between each other.
"Eric bouxirot" <rickou@xxxxxxxxxx> wrote in message news:mn.8b0c7d6930395ddf.56407@xxxxxxxxxxxxx
hi,
i'd like to do a "cast", who seem to be very complicated in .NET. in C standard it's so easy...
i explain :
i have made an app based on plugin architecture in VB.NET. all work fine..
but I want to avoid to the maximum to modify the interface at each new plugin feature request from main app, i defined a function like this :
Public Function Host_GetObject(ByVal FonctionName As String, Optional ByVal Parameters() As Object = Nothing) As Object() Implements ENPI.Interfaces.IHost.Host_GetObject
this function get 1 parameter to tell witch "function" to do and 1 array of object (defined by the function) to optionals parameters of this function.
this function return an array of object (content defined by the "function" entry parameter)
i put this function in my interface between the main app and plugin. no pb at this point.
if i use it with framework types, i get no problems.
But now, i want to return (in the array of object) a simple data structure (no class !) like this :
Private Structure StrPIsName
Friend PIName As String
Friend PIAssyName As String
End Structure
the main app can make the array of object from array of StrPIsName. good.
in the plugin, i get the array of object. good too.. but each object is typed with mainapp.StrPIsName all this is normal.
but for me, for raisons i tell before, i don't want to put the structure in the interface. (to avoid to recompil all plugin if i add or change the structure to the interface..)
then, since my plugin does not have the reference to mainapp.StrPIsName but to it's own StrPIsName, the cast can't be made.
do you understand what i mean ?
the end goal is to be able to make some enhancement or changes in the main app and somme plugin or new plugins needs without the need to recompil all other plugins.
i don't want to have many auxilliary DLL to get many interfaces between main app and plugins too.
in fact, i want to do something (perhaps not good in .NET) like in standard C :
toto = (mycast) tata;
HELPPP !!
.
- Follow-Ups:
- Re: force cast of object to mytype...
- From: Eric bouxirot
- Re: force cast of object to mytype...
- References:
- force cast of object to mytype...
- From: Eric bouxirot
- force cast of object to mytype...
- Prev by Date: Re: Service not going to 'Started'
- Next by Date: Re: Datagridview columns: can they be extended?
- Previous by thread: force cast of object to mytype...
- Next by thread: Re: force cast of object to mytype...
- Index(es):
Relevant Pages
|