473,626 Members | 3,265 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referencing a type w/o included source?

Say I have a library (A.dll) with a method that accepts a collection of
a specific type. The type is defined in B.dll. In A.dll, I need to
loop through this collection and reference fields of the type.

For example, a Person type. It may have arm, leg, feet, and hands.
Hands is a collection containing types of fingers. The only way to get
at fingers is by accepting the parameter as its true type. This means
I'll need a file reference to B.dll so I can declare a variable of type
Person to hold the Person parameter coming in.

Is there a way to do this without including B.dll? I want A.dll to be
stand alone. Referencing B.dll means any application that uses A.dll
will need to drag around B.dll as well. Also, if the application is
already referencing B.dll, that means I'm redundant once the reference
to A.dll is made (since it is too referencing B.dll).

Some one may say to use an interface here. Just have all of the B.dlls
implement the interface. Any other library such as the application or
A.dll will reference the interface, which is a conduit to all of the
B+.dll libraries. That doesn't work either because if the application
is referencing the interface already and then includes A.dll, which
also references the interface, I'm still including the interface twice.

Is this good logic or am I mistaken in my thinking on it? Is there a
way to get at the type or specifically, something in the type without
declaring the type in A.dll? Does .NET 2.0 offer anything for this?

Thanks,
Brett

Jan 23 '06 #1
9 1587
Could you declare a class in A that inherits from the class in B and
make the A class be the instances in the collections?
That way the target app only needs to reference A, getting A.Class
instead of B.class.

There's also the whole partial class concept that I am not all over
yet. Perhaps it would work.. its a 2.0 thing I think, where you can
declare a partial class in your B.dll and then in your A.dll add some
minor functionality, or even none at all, but this might still make the
class be part of the new A.dll.
Sorry I can't test it right now. Perhaps one of these MCPs, MCSDs,
MCADs, UFOs, etc who frequent this forum can expand on the partial
class concept.

Steve

Jan 23 '06 #2
I think you are out of luck in terms of not having to include both files..

An easy way to look at it is:

If you want to create an instance of _any_ object type you need to reference
the assembly that includes that code and that assembly needs to be available
on the clients machine in order to run.

I wouldnt worry about "multiple" references either because it wont make your
application any bigger - it just informs .NET what assemblies you need in
order to work.

Hope this helps!

"Brett Romero" <ac*****@cygen. com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Say I have a library (A.dll) with a method that accepts a collection of
a specific type. The type is defined in B.dll. In A.dll, I need to
loop through this collection and reference fields of the type.

For example, a Person type. It may have arm, leg, feet, and hands.
Hands is a collection containing types of fingers. The only way to get
at fingers is by accepting the parameter as its true type. This means
I'll need a file reference to B.dll so I can declare a variable of type
Person to hold the Person parameter coming in.

Is there a way to do this without including B.dll? I want A.dll to be
stand alone. Referencing B.dll means any application that uses A.dll
will need to drag around B.dll as well. Also, if the application is
already referencing B.dll, that means I'm redundant once the reference
to A.dll is made (since it is too referencing B.dll).

Some one may say to use an interface here. Just have all of the B.dlls
implement the interface. Any other library such as the application or
A.dll will reference the interface, which is a conduit to all of the
B+.dll libraries. That doesn't work either because if the application
is referencing the interface already and then includes A.dll, which
also references the interface, I'm still including the interface twice.

Is this good logic or am I mistaken in my thinking on it? Is there a
way to get at the type or specifically, something in the type without
declaring the type in A.dll? Does .NET 2.0 offer anything for this?

Thanks,
Brett

Jan 23 '06 #3
A.dll is a utility file and really shouldn't include any of custom
types. That's probably how I should think of it and avoid trying to
figure out how to use a custom type in A.dll when it shouldn't be doing
anything with a custom type.

A.dll has an extended data grid control. I want to take in a
collection of a specific type and update a particular item in the
collection when some one updates a row on the grid. I can do all of
this in the calling form. I just wanted to completely abstract it into
the data grid, since this is a grid thing.

It starts getting very complicated. I'd also need a way to get at
fields in the collection. Also, other types will use the custom data
grid. A.dll would have to know all of those types. In the end, I'm
trying to make the custom data grid to specific when it should be very
generic. I start getting into IFs or Switches or multiple methods will
very similar code.

I'll leave the code in the application calling the grid. It can do all
of the specific work in the particular form. This way, the custom data
grid does not need to know anything about custom types. It can still
extend its row update event to the form, which will subscribe to that
event.

Hmmm, good for now I suppose.

Brett

Jan 23 '06 #4
Brett Romero wrote:
Say I have a library (A.dll) with a method that accepts a collection of
a specific type. The type is defined in B.dll. In A.dll, I need to
loop through this collection and reference fields of the type.

For example, a Person type. It may have arm, leg, feet, and hands.
Hands is a collection containing types of fingers. The only way to get
at fingers is by accepting the parameter as its true type. This means
I'll need a file reference to B.dll so I can declare a variable of type
Person to hold the Person parameter coming in.

Is there a way to do this without including B.dll? I want A.dll to be
stand alone.
In that case you logically *can't* have it referencing a type defined
in B.dll. It just wouldn't make sense.
Referencing B.dll means any application that uses A.dll
will need to drag around B.dll as well. Also, if the application is
already referencing B.dll, that means I'm redundant once the reference
to A.dll is made (since it is too referencing B.dll).

Some one may say to use an interface here. Just have all of the B.dlls
implement the interface. Any other library such as the application or
A.dll will reference the interface, which is a conduit to all of the
B+.dll libraries. That doesn't work either because if the application
is referencing the interface already and then includes A.dll, which
also references the interface, I'm still including the interface twice.


If you only have the interface declared in one place, it shouldn't
matter how many times you add references to it.

Jon

Jan 23 '06 #5
Brett Romero wrote:
A.dll is a utility file and really shouldn't include any of custom
types. That's probably how I should think of it and avoid trying to
figure out how to use a custom type in A.dll when it shouldn't be doing
anything with a custom type.

A.dll has an extended data grid control. I want to take in a
collection of a specific type and update a particular item in the
collection when some one updates a row on the grid. I can do all of
this in the calling form. I just wanted to completely abstract it into
the data grid, since this is a grid thing.


Are you using .NET 2.0? If so, the obvious solution would be to use
generics. If you need to do anything "to" the objects you're provided
with, include an interface and make that a constraint on the type.
Otherwise, just make it a CustomDataGrid< T> and you should be away.

Jon

Jan 23 '06 #6
How does CustomDataGrid< T> help me in A.dll? Wouldn't I still have to
this back to Person to reach all of its inner workings?

Thanks,
Brett

Jan 23 '06 #7
Brett Romero wrote:
How does CustomDataGrid< T> help me in A.dll? Wouldn't I still have to
this back to Person to reach all of its inner workings?


You haven't really said what the type in A.dll needs to do. If it just
needs to hold references to instances of Person and expose them in a
strongly typed way, generics is perfect. If it needs to do other
things, you could include an interface (in A) which Person implemented,
and then constrain the parameterised type to implement that interface.

Jon

Jan 23 '06 #8
The Person type that is passed into A.dll as a generic (hopefully)
contains an address collection. I may actually pass in the Person
collection, which contains person objects. Each address object in the
address collection of a Person object contains fields (address, city,
state, zip). Would I be able to access
PersonCollectio n[1].address[1].city in A.dll for example if the
PersonCollectio n type came in as a generic? How would that look in
code (caller and recipient)?

Thanks,
Brett

Jan 23 '06 #9
Brett Romero wrote:
The Person type that is passed into A.dll as a generic (hopefully)
contains an address collection. I may actually pass in the Person
collection, which contains person objects. Each address object in the
address collection of a Person object contains fields (address, city,
state, zip). Would I be able to access
PersonCollectio n[1].address[1].city in A.dll for example if the
PersonCollectio n type came in as a generic? How would that look in
code (caller and recipient)?


If the collection were actually MyCollection<Pe rson> (as created by B,
using MyCollection<T> from A, then as far as B were concerned it would
be returning Person in a strongly-typed way. If the collection class in
A.dll needs to do that indexing and look at the address, then I'd
suggest it's not a good candidate for being in a general purpose
library in the first place.

Have a look at List<T> for examples, and try creating (say) a
List<Stream> - the indexer will return a Stream, strongly-typed, so you
could do list[0].Read(...) with no problems. Apply the same to your own
collection and your own element type and I believe that solves your
concerns.

Jon

Jan 23 '06 #10

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

Similar topics

6
2871
by: Julie | last post by:
I have a situation where I have multiple objects that aren't related in any way (no base class), but all have a couple of common methods/properties. I'm looking for a clean way to call a particular method/property for the object, w/o having to resort to a bunch of if-is-cast statements. Here is what I'd like to be able to do: object source = GetSource(); object width = some_mystery_function(source, "Width");
6
5426
by: tshad | last post by:
The error I am getting is: ******************************************************************* Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid. Source Error: Line 144: firstName.text = ClientReader("firstName") Line 145: lastName.text = ClientReader("lastName")
3
2909
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line 347: 'response.Write(sql2)
0
1084
by: Gamesetal | last post by:
I am searching for a simple example of a File Type DSN with instructions for an asp page to communicate with an Access 2000 database through ODBC - but I cannot find one anywhere - so frustrating... I just bought Microsofts Book on Access 2000 but nothing except sql examples!!!!! Help me please - TIA John
0
1692
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by calling getDataGridReference and returning the DataList's selectedIndex)
3
2135
by: niks | last post by:
I'm a javascript novice trying to write a client-side program that needs to examine the text of some included code. Suppose you have the following snippet in an html document: <script id="included" src="inc.js" type="text/javascript"></script> I want to be able to write a function along the following lines: function inspect() {
8
13189
by: Rob T | last post by:
When I was using VS2003, I was able to compile my asp.net project locally on my machine and copy it to the production server and it would run just fine. I've now converted to VS2005. The project compiles & runs fine locally, but when I copy to the production machine, I get this error: Parser Error Message: Could not load type 'Global'. Source Error: Line 1: <%@ Application Codebehind="Global.asax.vb" Inherits="Global" %> Source...
1
1650
by: wbsurfver | last post by:
I am looking for a PHP package which can do a series of Q&A type of forums. It should be unthreaded, 1 question followed by a series of answers. It should work with mysql and be relatively easy to work into a site being customizable etc so that a look and feel can be created around it. Any recommendations ?
4
6469
by: Siegfried Heintze | last post by:
Below is a program I'm translating from C# to VB. The C# version works. I don't understand how to specify the type on line 55. XmlSerializer wants a type and I tried to follow the example at http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx but it is still not working. I' having a similar problem on line 34 where the XmlAttributeAttribute can take a type argument. Thanks, Siegfried
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5574
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
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 we have to send another system
1
1808
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.