By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,827 Members | 2,140 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,827 IT Pros & Developers. It's quick & easy.

Partial assemblies

P: n/a
I need to add methods without subclassing to run time compiled assembly at
design time so that reflection also works .

I need to define single type methods in two assemblies.

I created project1 containing

public partial class Class1 {
public string Test1() {
return "";
}
}

and project2 containing

public partial class Class1 {
public string Test2() {
return Test1();
}
}

and added reference to project1 into project2.
Building solution causes error

The name 'Test1' does not exist in the current context

at line

return Test1();

How to fix ?
How to use this type of class extension ?

Andrus.

Jan 6 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Andrus <ko********@hot.eewrote:
I need to add methods without subclassing to run time compiled assembly at
design time so that reflection also works .
You can't do so.

<snip>
How to fix ?
How to use this type of class extension ?
You can't. There's no such thing as a "partial assembly". Partial types
are entirely a compile-time business in the first place - the CLR has
no concept of it.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Jan 6 '08 #2

P: n/a
Andrus wrote:
I need to add methods without subclassing to run time compiled assembly at
design time so that reflection also works .

I need to define single type methods in two assemblies.

I created project1 containing

public partial class Class1 {
public string Test1() {
return "";
}
}

and project2 containing

public partial class Class1 {
public string Test2() {
return Test1();
}
}

and added reference to project1 into project2.
There is no easy way.

I suppose you could make the two assemblies and have a bootstrapping
module which takes the two assemblies and combines them.

You'd need to:

1) Add all the methods into a single class (perhaps using attributes to
indicate which classes should be combined, or just requiring them to
have the same name and be in the same namespace).

2) When you add methods to the new assembly, you'll need to modify the
IL so that method calls point to the method in the new assembly.

Debugging could quickly become very painful though.

Alun Harford
Jan 6 '08 #3

P: n/a
I think it's possible using AOP techniques. You should look at the Mixin
concept which is relatively close to what your are descibing (yet different).

A technical solution I suggest is to use the open source library named Cecil
(http://www.mono-project.com/Cecil) which is able to do these AOP techniques.
Thus you can open the assemblies and fusion your classes into a new one or in
an existing one. An attribute could be placed on one of the classes to
describe the link, and let a tool fusion all related classes automatically.

The only drawback is that it can only be done after compile time. At least,
using an interface could be a solution to it.
Jan 15 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.