Re: force cast of object to mytype...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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



.



Relevant Pages

  • Re: Index implementation design
    ... I have this thing about every app I have ever written must only use the VB6 run time files only. ... A temp string array is created. ... Read thru the array of newly sorted array Adding the Keys of the collection to the array ...
    (comp.lang.basic.visual.misc)
  • Re: call an executable with array of strings parameter
    ... Thanks, I started looking at your references, but it will take my a while to ... I would like to use an array of strings as a parameter for calling my ... executable, not just one string. ... passing even such a long string to another app. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Design help with File I/O and searching?
    ... Dictionary(of String, String) in a Smart Device project in VS2005... ... which is .NET equivilent of the Dictionary class as per Smalltalk. ... I just didn't quite know how to get the data into an array, ... I need to create an app that runs on a PDA type scanner running Win ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: call an executable with array of strings parameter
    ... Could you please explain a little more about a messaging system ... I would like to use an array of strings as a parameter for calling my ... ShellExecuteInfo only seems to allow one string. ... passing even such a long string to another app. ...
    (microsoft.public.win32.programmer.networks)
  • force cast of object to mytype...
    ... i have made an app based on plugin architecture in VB.NET. ... this function get 1 parameter to tell witch "function" to do and 1 array of object to optionals parameters of this function. ... i put this function in my interface between the main app and plugin. ...
    (microsoft.public.dotnet.languages.vb)