The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

c# - sharing structs via dlls

Hi all,

I have a plugin-based program (in C#) in which the plugins are dll. From some of them I need to return an arraylist of structs, but how do I make the structs in question known throughout the entire app ?
Berry from Dingle
Friday, October 14, 2005
 
 
Create a Custom Attribute that can be applied to a struct.  Then label your structs with your new Attribute, before getting your reflection code to search for all occurances of this new Attribute.

If you need an example, I can oblige.
Edward James Send private email
Friday, October 14, 2005
 
 
I think I may have mis-understood your question.

Maybe you need to look into using dependency injection (google it) in your application.
Edward James Send private email
Friday, October 14, 2005
 
 
I believe that you can marshal them as a class.
Arafangion Send private email
Friday, October 14, 2005
 
 
Extract your plugin architecture to a separate assembly so that....

MyApp.exe --> PluginArchitecture.dll
MyPlugin.dll --> PluginArchitecture.dll

where --> means "references"
Jeff Mastry Send private email
Friday, October 14, 2005
 
 
Hmm interesting, that last post. I solved the trouble by using classes instead of structs, though. Seems to work, but maybe not that elegant.

Thanks!
Berry from Dingle
Friday, October 14, 2005
 
 
I'm not sure if the following is that relevant, but structs are value types. You can't have shared references to a value type. Every assignment to a struct creates a separate copy of that struct, so if you change the original one, none of the other variables will change (and vice-versa).
Mark Cidade Send private email
Friday, October 14, 2005
 
 
"Hmm interesting, that last post. I solved the trouble by using classes instead of structs..."

Perhaps I misunderstood what you were trying to accomplish. I thought the problem you had was making the structure TYPE known to your plugins.
Jeff Mastry Send private email
Saturday, October 15, 2005
 
 
Although "solved", I'll try to be more clear:

I have a struct, for simplicity, we'll say it's

struct thestruct
{
  string blah1;
  string blah2;
};

I want to create objects using this struct throughout the application, including the plugins (dlls), and if one of the dlls functions return an arraylist of objects (thestruct), i can cast it to this struct and access it's contents, even if it's another dll calling the function.

:-\ i'm terrible at explaining, as you see, but hopefully you'll get the gist.
Berry from Dingle
Saturday, October 15, 2005
 
 
Berry,

You'll end up in versioning problems. Make sure you've got your interfaces right. Refactor if they're wrong.
Dino Send private email
Saturday, October 15, 2005
 
 
Berry from Dingle... nice name.
dingleberry
Saturday, October 15, 2005
 
 
Slightly off the point, but it's generally not good practice to go returning ArrayLists from public methods or properties. Too open to abuse. Return an Array instead, which has the added bonus of type safety (if your type is unknown at compile time, you can return an Array of Object and suffer the boxing penalty, and of course generics does away with this problem entirely).

I very much treat containers as internal objects, and stick with primitives and strongly-typed objects at the API level.

Just my $0.02.
.NET Guy
Monday, October 17, 2005
 
 
Thanks for the replies... On the topic of interfaces, anyone got url(s) for a decent implementation?
Berry from Dingle
Monday, October 17, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz