473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Partial assemblies

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
3 1402
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nospam | last post by:
I just read on Slash Dot about partial types. Now, is it possible to have a code behind split over two pages but still referencing the same .aspx file??? If so, that would be really nice as...
1
by: Afaq | last post by:
Hi, After adding large number of empty resource files (which will be updated later), we are not able to compile the project. the following is the output of the build process. It fails while...
9
by: Gomaw Beoyr | last post by:
Two question about the "partial classes" (in the next wersion of ..NET). Question 1 ========== Will partial classes (in the next version of C#) have to be declared "partial" in ALL places. ...
3
by: Vadim | last post by:
I want to make strong name for may apllication assemblies, but I don't know where and how can I do it in Whidbey. Help me please
16
by: pawel.pabich | last post by:
Hajo, I would like to have 2 my own partial classes. For example: Default.aspx.cs Default2.aspx.cs and they both will relate to Default.aspx page.
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
2
by: Tommaso Caldarola | last post by:
Can I use partial class on different assembly?
3
by: Aryan | last post by:
Hi, I have problem in creating Partial Class for ASPX pages. As my Codebase file for ASPX page is having more then 2500 lines of code. So its very hard to maintain the code. So I wanted to know,...
1
by: hardieca | last post by:
Hi! I decorate my unfinished classes and methods with a custom TODO attribute (as in things To Do). Using reflection, I am then able to parse through my classes and output all TODOs to a list I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.