force cast of object to mytype...

E

Eric bouxirot

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 !!
 
J

Jay B. Harlow [MVP - Outlook]

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.
 
C

Cor Ligthert [MVP]

Eric,

A little bit in addition to Jay told in a more direct way,

Try to think in dotNet and forget C++ in your first attempts.

I do'nt know if you saw this message in this newsgroup from yesterday (for
me).

http://groups.google.com/group/microsoft.public.dotnet.languages.vb/msg/7efd4dff447524ffCor"Eric bouxirot" <[email protected]> schreef in berichthi,>> i'd like to do a "cast", who seem to be very complicated in .NET. in Cstandard 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 newplugin feature request from main app, i defined a function like this :>> Public Function Host_GetObject(ByVal FonctionName As String, OptionalByVal Parameters() As Object = Nothing) As Object() ImplementsENPI.Interfaces.IHost.Host_GetObject>> this function get 1 parameter to tell witch "function" to do and 1 arrayof object (defined by the function) to optionals parameters of thisfunction.> 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 pbat 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 istyped with mainapp.StrPIsName all this is normal.>> but for me, for raisons i tell before, i don't want to put the structurein the interface. (to avoid to recompil all plugin if i add or change thestructure to the interface..)>> then, since my plugin does not have the reference to mainapp.StrPIsNamebut 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 mainapp and somme plugin or new plugins needs without the need to recompil allother plugins.>> i don't want to have many auxilliary DLL to get many interfaces betweenmain app and plugins too.>> in fact, i want to do something (perhaps not good in .NET) like instandard C :>> toto = (mycast) tata;>> HELPPP !!>>
 
E

Eric bouxirot

hi,
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.

ok!! i know this method, I don't know why but I didn't think of it.
thank !
.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


in two assemblies (MainApp & SomeAddin) are distinct types & cannot be cast
between each other.

ok i have add the structure to the interface, then i try to user plugin
referenced to old dll with new dll including structure for new plugin,
then i work fine....
i don't like this, but it work...

thank
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top