Navigation


contactdonateaop.net



Interface Implementation by Aggregation

posted by gael    Sunday, November 26th, 2006 at 12:55 pm

I have written that the newly redesigned Code Weaver now support type-level advices (well, to be precise, type-level join points). The first implementation is the new AggregationAspect
in PostSharp Laos.

So what’s aggregation?

Say you want to implement a collection (ICollection) based on an ArrayList, but you want to hide ArrayList and don’t want to implement each method manually. PostSharp can do it for you.

Look at the following code sample:

[SimpleAggregate(
  ImplementationType=typeof(ArrayList),
  InterfaceType=typeof(ICollection))]
internal class AggregatedCollection
{
}

After processing by PostSharp, the AggregatedCollection class will implement the ICollection collection using the ArrayList implementation.

Looks magic? If you inspect the generated code (the Roeder’s Reflector is always useful for this), you will see a new field ~aggregated~0 of type ICollection and all methods of this interface, for instance:

IEnumerator IEnumerable.GetEnumerator()
{
  return this.~aggregated~0.GetEnumerator();
}

The aggregated object is constructed inside the constructor of AggregatedCollection:

public AggregatedCollection()
{
  this.~aggregated~0 = (ICollection)
 ~PostSharp~Laos~Implementation.customAttribute0.
           CreateAggregatedObject(this);
}

Still looks magic?

Redesign of the Code Weaver

posted by gael    Sunday, November 26th, 2006 at 12:23 pm

The ones who already use the Code Weaver will maybe get angry but that’s something I needed to do before going beta: I have redesigned quite deeply the low-level code weaver. Most changes are documented in the CHANGELOG.txt file.

So what has changed?

First, the notions of local and global advices has been deprecated. There is instead a unified notion of method-level advices and unified semantics to express what is called elsewhere pointcuts, i.e. to apply advices to join points. When you add an advice to the weaver, you can now specify on which methods it applies and on which operands. We use the IEnumerable interface to pass sets of methods and operands, so it should be forward compatible with C# 3.0 / LINQ.

If I said method-level advices, that’s because PostSharp now supports also type-level advices: the only join point currently supported is after instance construction, i.e. in the constructor, just after the base constructor has been called.

Secondly, you cannot call the weaver for individual methods. The Weave method now weaves the complete module according to the advices that were previously added to it.

And finally, the IAdviceProvider has changed. There is now a single ProvideAdvices method in which you should add advices to the given weaver. That’s all.

The internal workings have been considerably optimized to work with operand-sensitive join points. Say you want to intercept all calls to the Thread.Sleep() method. You create an advice and apply it to the join points of kind InsteadOfCall with operand Thread.Sleep. Before redesign, the weaver would have woven every method of the module. But now, it will only weave methods that effectively use the Thread.Sleep method.

In order to make it possible, I have implemented the new task IndexUsagesTask, which reads all method bodies an indexes ‘uses’ and ‘used-by’ relationships. Why is it better than the previous design? First, because inspection algorithm of this task is much simpler than the one of the weaver. Secondly, because the same information can be used by other tasks.

So at the end of the day, will you be still angry of this design change? Hopefully not, because these changes don’t affect your code too much. All you have to do is to change your implementation of IAdviceProvider. And this new design is much better and is prepared for the future.

So let’s go!

Remote Host

posted by gael    Sunday, November 26th, 2006 at 12:16 pm

I wrote in the previous post that PostSharp now offers more possibilities for the host to customize the execution process, for instance phased execution and events. In order to enable it, we missed a functionality: to be able to run host code in the PostSharp application domain, not only in the host AppDomain.

This is the role of the new concept of local host. The local host is an object that resides in the PostSharp application domain between the PostSharpObject and the host object residing in the host application domain (IPostSharpHost). The whole communication between the PostSharpObject and the remote host now goes through the local host. We provide a default implementation in the PostSharpLocalHost class, but you can override it and pass your own implementation using the LocalHostImplementation property of the PostSharpObjectSettings object.

Phased Execution

posted by gael    Sunday, November 26th, 2006 at 11:57 am

There is a lot of new things to tell today. To make it simpler I will make a post for each of them. Let me start with the first: phased execution.

You probably know that PostSharp projects are composed of tasks. Indexing types is a task, weaving is a task, and even compiling back the code is a task. What you maybe don’t know if that tasks are grouped in phase. PostSharp defines four standard phases: load, analyze, transform and generate.

When you execute a single project, i.e. when you transform a single module, the situation is trivial: we execute one phase after the other.

However, when you transform multiple modules in a single invocation of PostSharp, then you have the question: should I analyse all module, then transform them all, then compile them all, or should I process one module completely, then go to the next one.

You have now the choice. PostSharp can do both: the phases and the sequential execution.

I have defined a new property ProjectExecutionOrder on the PostSharpObjectSettings object so you can choose. If you host PostSharp yourself, of course! If you don’t, anyway, each invocation of PostSharp processes only one module and this discussion is useless.

But if you do host PostSharp, you have the possibility to execute custom code between phases. If you really need this (and think twice if it cannot be implemented as a normal task), look at the events PhaseExecuting and PhaseExecuted of the PostSharpObject event. How would you get a chance to register your own event handlers? Good question, you have to implement a local host. I explain it in my next post.

Execute PostSharp at runtime

posted by gael    Thursday, November 16th, 2006 at 9:00 pm

Like week-end I have been working on a breaking feature of PostSharp: the possibility to use it at runtime. So PostSharp is not only a post-compiler any more.

Of course, the core technology is still and will stay MSIL manipulation. When I say that PostSharp can be used at runtime, I mean that .NET modules can be woven just before they are loaded by the Virtual Runtime Engine (VRE). After they have been loaded, they cannot be modified. Obviously.

Why at runtime?

Weaving an assembly at runtime makes sense principally within application servers. These servers typically offer services like transactions or persistence. These aspects may be defined, for instance, at deployment time in a management console. So they have to be woven outside the development environment.

How does it work?

If you liked the Platform Infrastructure (what makes PostSharp really different from an ordinary IL reader/writer), you will have another reason to be satisfied: the same infrastructure is now available at runtime. It has been redesigned to make no difference between runtime and compile-time use. The MSBuild task and the command-line utility have been corrected to use the new design.

Concretely, I defined a new object PostSharpObject that is the entry point for the Platform Infrastructure. You can create an instance (either in the current AppDomain either in a private one) using the PostSharpObjectFactory — in any case you will only get the interface IPostSharpObjectFactory. This interface has a single method InvokeProjects, that allows to execute a set of project. Each project has its own source module and its own properties. This satisfies most compile-time scenarios and even some runtime ones!

Things become more interesting when you need to weave assembly in deep-first order. That means that you need to weave referred assemblies first, then referring. This is typically the case when you need to change the public interface of assemblies (for instance change fields into properties). In this case, you have to implement the new IPostSharpHost interface. This interface is called every time an assembly reference should be resolved. You get the opportunity to tell how assemblies should be processed, i.e. you can ask there to transform it using a project and given parameters.

On the other extreme, lazy weaving of assemblies (weave just before the assembly is required by the VRE) needs a more complex interaction between the host and PostSharp. The host has to implement the AppDomain.AssemblyResolve event.

Do you want to try?

The changes have been merged in the trunk of the SVN repository. I have built a prerelease of the 1.0 Beta 1 version. It is largely documented and I wrote a sample.

Feedback welcome!

Download Adobe InDesign CS2 v4.0 OEM Cheap OEM Software. Buy and download oem Adobe, oem Autodesk, oem Macromedia, oem Microsoft at SoftwareVending.com Download Adobe Acrobat 7.0 Pro OEMDownload Adobe Contribute CS3 OEM Online Casinogulfstream casino hollywood gun lake casino updated information hammond indiana casino hampton beach casino hampton nh Download Microsoft Windows Millennium Edition OEMDownload Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEM Download Adobe Acrobat 3D OEM Download Adobe Photoshop CS3 French OEMDownload Adobe Dreamweaver CS3 OEM Download Adobe Acrobat 6 professional OEM Download Adobe Premiere Elements 3.0 OEMDownload Adobe Premiere Pro 7 OEM Download Adobe Acrobat 7.0 Pro OEM Download Adobe Streamline 4.0 OEMDownload Adobe Contribute CS3 OEM Download Adobe Acrobat 8 OEM Download Microsoft Windows XP Professional SP2 OEMDownload Adobe InDesign CS2 v4.0 OEM Download Adobe Acrobat Distiller 6 OEM Download Adobe Acrobat 7.0 Pro OEMDownload Adobe Acrobat 6 professional OEM Download Adobe After Effects 7 OEM Download Adobe Type Manager Deluxe 4.1 OEMDownload Adobe Photoshop CS3 French OEM Download Adobe After Effects CS3 OEM Download Microsoft Windows Server 2008 OEMDownload Adobe Acrobat 3D OEM Download Adobe Atmosphere 1.0 OEM Download Adobe Photoshop CS2 + Image ready CS2 OEMDownload Adobe InDesign CS2 v4.0 OEM Download Adobe Audition 1.5 OEM Download Adobe Creative Suite 3 Design Premium OEMDownload Microsoft Windows Millennium Edition OEM Download Adobe Contribute CS3 OEM Download Adobe Contribute CS3 OEMDownload Adobe Illustrator CS OEM Download Adobe Creative Suite 2 Premium OEM Download Adobe InCopy CS OEMDownload Adobe Premiere PRO 2.0 OEM Download Adobe Creative Suite 3 Web Premium OEM Download Adobe Creative Suite 3 Design Premium OEMDownload Adobe Acrobat 7.0 Pro OEM Download Adobe Creative Suite 3 Design Premium OEM Download Adobe Pagemaker 7 OEMDownload Adobe Illustrator CS3 OEM Download Adobe Creative Suite Standard Full OEM Download Adobe Premiere Pro 7 OEMDownload Adobe Photoshop Lightroom 1.3 Multilingual OEM Download Adobe Dimensions 3.0 OEM Download Adobe Dreamweaver CS3 OEMDownload Adobe Creative Suite 3 Design Premium OEM Download Adobe Dreamweaver CS3 OEM Download Adobe Photoshop CS + Adobe ImageReady CS OEMDownload Adobe Photoshop Lightroom 1.3 OEM Download Adobe Encore DVD 1.5 OEM Download Microsoft Windows XP Professional x64 OEMDownload Adobe Contribute CS3 OEM Download Adobe Fireworks CS3 OEM Download Adobe InCopy CS OEMDownload Adobe Photoshop CS + Adobe ImageReady CS OEM Download Adobe Flash CS3 Professional OEM Download Adobe Creative Suite Standard Full OEMDownload Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEM Download Adobe Flex 2 OEM Download Adobe Creative Suite 3 Web Premium OEMDownload Adobe GoLive CS2 V 8.0 OEM Download Adobe Flex Builder Professional 3.0 OEM Download Microsoft Windows Server 2008 OEMDownload Adobe Premiere Elements 1.0 OEM Download Adobe FrameMaker 7.0 OEM Download Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEMCheap OEM Software. Buy and download oem Adobe, oem Autodesk, oem Macromedia, oem Microsoft at SoftwareVending.com Download Adobe GoLive CS V 7.0 PC OEM Download Adobe Creative Suite Standard Full OEMDownload Adobe InCopy CS OEM Download Adobe GoLive CS2 V 8.0 OEM Download Microsoft Windows XP Professional x64 OEMDownload Adobe Premiere PRO 2.0 OEM Download Adobe Illustrator 10 OEM Download Adobe Acrobat 8 OEMDownload Adobe GoLive CS V 7.0 PC OEM Download Adobe Illustrator CS OEM Download Adobe Creative Suite Standard Full OEMDownload Microsoft Windows Server 2008 OEM Download Adobe Illustrator CS2 OEM Download Adobe Photoshop Elements 5 OEMDownload Adobe Illustrator CS3 OEM Download Adobe Illustrator CS3 OEM Download Adobe Dreamweaver CS3 OEMDownload Adobe Premiere PRO 2.0 OEM Download Adobe InCopy CS OEM Download Adobe Creative Suite Standard Full OEMDownload Adobe Creative Suite 2 Premium OEM Download Adobe InDesign CS OEM Download Adobe Creative Suite 3 Web Premium OEMDownload Adobe Photoshop 7 OEM Download Adobe InDesign CS2 OEM Download Adobe Contribute CS3 OEMDownload Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEM Download Adobe InDesign CS2 v4.0 OEM Download Adobe Acrobat 7.0 Pro OEMDownload Adobe Creative Suite Standard Full OEM Download Adobe Pagemaker 7 OEM Download Adobe Illustrator CS2 OEMDownload Adobe Pagemaker 7 OEM Download Adobe Photoshop 7 OEM Download Adobe Type Manager Deluxe 4.1 OEMDownload Adobe Premiere Pro 7 OEM Download Adobe Photoshop CS + Adobe ImageReady CS OEM Download Adobe GoLive CS2 V 8.0 OEMDownload Adobe FrameMaker 7.0 OEM Download Adobe Photoshop CS2 + Image ready CS2 OEM Download Adobe Photoshop CS3 Extended OEMDownload Adobe Premiere Pro 1.5 OEM Download Adobe Photoshop CS3 Extended OEM Online Casinogulfstream casino hollywood gun lake casino updated information hammond indiana casino hampton beach casino hampton nhDownload Adobe Dimensions 3.0 OEM Download Adobe Photoshop CS3 French OEM Download Adobe InDesign CS2 v4.0 OEMDownload Adobe Photoshop Lightroom 1.3 OEM Download Adobe Photoshop Elements 4.0 OEM Download Adobe Acrobat 7.0 Pro OEMOnline Casinogulfstream casino hollywood gun lake casino updated information hammond indiana casino hampton beach casino hampton nh Download Adobe Photoshop Elements 5 OEM Download Adobe Acrobat 3D OEMDownload Adobe InDesign CS OEM Download Adobe Photoshop Lightroom 1.3 OEM Download Adobe Type Manager Deluxe 4.1 OEMDownload Adobe Streamline 4.0 OEM Download Adobe Photoshop Lightroom 1.3 Multilingual OEM Download Adobe Premiere Pro 7 OEMDownload Adobe Dimensions 3.0 OEM Download Adobe Premiere Elements 1.0 OEM Download Adobe Photoshop CS3 Extended OEMDownload Adobe Photoshop CS + Adobe ImageReady CS OEM Download Adobe Premiere Elements 3.0 OEM Download Microsoft Windows Millennium Edition OEMDownload Adobe Acrobat 6 professional OEM Download Adobe Premiere Pro 1.5 OEM Download Microsoft Windows XP Professional x64 OEMDownload Adobe Photoshop 7 OEM Download Adobe Premiere PRO 2.0 OEM Download Adobe Photoshop CS3 French OEMDownload Adobe Streamline 4.0 OEM Download Adobe Premiere Pro 7 OEM Download Microsoft Windows NT 4.0 Terminal Server OEMDownload Adobe FrameMaker 7.0 OEM Download Adobe RoboHelp 6 OEM Download Adobe Pagemaker 7 OEMDownload Adobe Premiere Elements 1.0 OEM Download Adobe Streamline 4.0 OEM Download Adobe Contribute CS3 OEMDownload Adobe Acrobat 7.0 Pro OEM Download Adobe Type Manager Deluxe 4.1 OEM Download Adobe Acrobat 6 professional OEMDownload Adobe InDesign CS2 OEM Download Microsoft Digital Image Suite 2006 11.0 OEM Online Casinogulfstream casino hollywood gun lake casino updated information hammond indiana casino hampton beach casino hampton nhDownload Adobe RoboHelp 6 OEM Download Microsoft Exchange Server Enterprise 2003 OEM Download Adobe Creative Suite 2 Premium OEMDownload Adobe Creative Suite 2 Premium OEM Download Microsoft Frontpage 2003 OEM Download Adobe GoLive CS V 7.0 PC OEMDownload Adobe InDesign CS2 OEM Download Microsoft Money 2007 Deluxe OEM Download Adobe Photoshop CS3 Extended OEMDownload Adobe Premiere Pro 1.5 OEM Download Microsoft Office 2000 Premium Edition OEM Download Adobe Acrobat 3D OEMDownload Microsoft Windows NT 4.0 Terminal Server OEM Download Microsoft Office 2003 Professional Edition OEM Download Adobe InDesign CS2 OEMDownload Adobe Creative Suite 3 Web Premium OEM Download Microsoft Office 97 SR2 OEM Download Microsoft Windows Server 2003 Enterprise Edition OEMDownload Adobe InDesign CS2 OEM Download Microsoft Office SharePoint Designer 2007 OEM Download Adobe Illustrator CS3 OEMDownload Adobe Premiere PRO 2.0 OEM Download Microsoft Office Visio Professional 2007 OEM Download Adobe Premiere Elements 1.0 OEMCheap OEM Software. Buy and download oem Adobe, oem Autodesk, oem Macromedia, oem Microsoft at SoftwareVending.com Download Microsoft Office XP Professional OEM Download Adobe Illustrator 10 OEMDownload Adobe GoLive CS V 7.0 PC OEM Download Microsoft OneNote 2003 Pro OEM Download Adobe RoboHelp 6 OEMDownload Adobe Photoshop CS3 Extended OEM Download Microsoft PhotoDraw 2.0 OEM Download Adobe FrameMaker 7.0 OEMDownload Adobe Streamline 4.0 OEM Download Microsoft Picture It Photo Premium 9 OEM Download Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEMDownload Adobe Acrobat 8 OEM Download Microsoft Plus! XP OEM Download Adobe Illustrator CS2 OEMDownload Adobe Photoshop 7 OEM Download Microsoft SQL Server 2000 Enterprise Edition OEM Download Adobe Creative Suite 2 Premium OEMDownload Adobe RoboHelp 6 OEM Download Microsoft Streets & Trips 2006 OEM Download Adobe Photoshop Elements 4.0 OEMDownload Adobe Acrobat 7.0 Pro OEM Download Microsoft Streets and Trips 2004 OEM Download Adobe Acrobat 7.0 Pro OEMDownload Adobe Illustrator CS2 OEM Download Microsoft Visio 2003 Pro OEM Download Adobe Photoshop CS2 + Image ready CS2 OEMDownload Adobe Photoshop 7 OEM Download Microsoft Visual Basic 6.0 Pro OEM Download Adobe Dreamweaver CS3 OEMDownload Adobe RoboHelp 6 OEM Download Microsoft Visual Studio Professional Edition 2005 MSDN OEM Download Adobe Premiere Elements 3.0 OEMDownload Adobe Acrobat 6 professional OEM Download Microsoft Windows 2000 Advanced Server with SP4 OEM Download Adobe Illustrator CS OEMDownload Adobe Illustrator 10 OEM Download Microsoft Windows 2000 Professional with SP4 OEM Download Adobe Streamline 4.0 OEMDownload Adobe Photoshop CS3 French OEM Download Microsoft Windows 98 Second Edition OEM Download Adobe InDesign CS2 OEMDownload Adobe Type Manager Deluxe 4.1 OEM Download Microsoft Windows Millennium Edition OEM Download Adobe Acrobat 8 OEMDownload Adobe GoLive CS V 7.0 PC OEM Download Microsoft Windows NT 4.0 Terminal Server OEM Download Adobe Premiere Elements 3.0 OEMDownload Adobe Photoshop CS2 + Image ready CS2 OEM Download Microsoft Windows Server 2003 Enterprise 64 Bit x64 OEM Download Adobe Creative Suite 3 Design Premium OEMDownload Adobe Streamline 4.0 OEM Download Microsoft Windows Server 2003 Enterprise Edition OEM Download Adobe Streamline 4.0 OEMDownload Adobe Acrobat 8 OEM Download Microsoft Windows Server 2008 OEM Download Adobe GoLive CS V 7.0 PC OEMDownload Adobe Illustrator CS OEM Download Microsoft Windows XP Professional SP2 OEM Download Microsoft Windows Server 2003 Enterprise Edition OEMDownload Adobe Photoshop Elements 5 OEM Download Microsoft Windows XP Professional x64 OEM Download Adobe Illustrator CS3 OEMDownload Microsoft Windows NT 4.0 Terminal Server OEM Download Microsoft Works 7 OEM Online Casinogulfstream casino hollywood gun lake casino updated information hammond indiana casino hampton beach casino hampton nh