473,473 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

force cast of object to mytype...

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 !!
Sep 17 '06 #1
5 2619
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" <ri****@rickou.netwrote in message
news:mn***********************@rickou.net...
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 !!

Sep 18 '06 #2
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" <ri****@rickou.netschreef in berichtnews:mn***********************@rickou.net.. .hi,>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>thi s 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 !!>>

Sep 18 '06 #3
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 !
>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.
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
Sep 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: zhou | last post by:
Hi there, We have a compiler specific issue which requires us to force template instantiation. This works fine. The problem comes when I try using std:find() on vector. Since vector has no member...
2
by: Laura | last post by:
In C#, the method was dynamically invoked through reflection. But How do we dynamically cast the return object to its own type? Here is the sample code: // dynamically invoke the method Object...
1
by: Flix | last post by:
When making c# programs, I usually write code like this: SomeType myType=null; void Init() { myType=new SomeType(); }
4
by: KC | last post by:
Could some one explain to me the casting rules for sending generic lists, ex. List<Person>, to a function that accepts List<object>? I cannot get the following easy-cheesy app to work. I get the...
6
by: Nick Weekes | last post by:
Hi all, I am trying to cast a Double (its actually the NextDouble method of the Random class, but could be any type of number) to a Type via its name. Im trying the following syntax: ...
3
by: Charles Law | last post by:
I have the following lines Dim t As Type = GetType(MyType) Dim serialiser As New XmlSerializer(t) I want to be able to do the following with a FileStream fs Dim instance As MyType ...
4
by: jkhome | last post by:
Please can someone help me. I have an arraylist which contains objects how do i go about reading the data out of the objects in the arraylist, code example below.. I really have no idea how to do...
3
by: Tao | last post by:
hi. guys, I have two AppDomains, AppDomain0 and AppDomain1. In AppDomain1, I got a class implements an interface IInterface0. In AppDomain0, I also define a IInterface0, the code of two...
4
by: Jamie McQuay | last post by:
I receive an object from an event and I need to go through a long list of types to determine the type to cast to. For example if (myObject is A) { propertyGrid.SelectedObject = (A)myObject; }...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.