|
|
|
Community Member
|
|
Hi!
After struggling a bit with IL development I'd like to say that
I have a dream <!-- s:) --> <!-- s:) -->
One day we'll be coding with Postsharp and will be able to do something like:
RealCSharpCodeEmitter.EmitBeforePropertySet( "if (!Object.Equals("+property.Name+",value) Debug.WriteLine(\"Property "+property.Name+" changing\");"
I do not know if it's possible at all to do so, but that'll be great.
|
|
|
|
|
Community Member
|
|
Nixoay-
In fact you do not need PostSharp to compile C# code.
It is build into .Net
See http://msdn.microsoft.com/en-us/library/microsoft.csharp.csharpcodeprovider.aspx
However, based on the code you provided, I do not think you need a low-level aspect which require custom weaving. For your particular example, you should make an OnFieldAccessAspect derived aspect and override the OnSetValue method. This, among others, is provided in the Laos assembly. These aspects come with their own weavers, so all you need to do is derive from the abstract aspect class, populate it with the functionality you want to provide, and then apply functionality as desired. Aspect classes are attributes, so just annotate the properties, or annotate at the class level to catch all the properties.
Please take a look at the XTrace sample, specifically the FieldAccessAttribute class. This will be a good starting point. Once you understand this you can look at functionality similar to what I think you're looking for in the PostSharp.Samples.Binding project.
Happy PostSharping!
-Chris
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
I think that what Nixoay means is that he wants to be able to emit C# code from inside PostSharp. This would be useful, indeed, to implement patterns like IClonable.
I have a good idea how to implement that - as usually, just no time and budget <!-- s;) --> <!-- s;) -->.
|
|
|
|
|
Community Member
|
|
Yes, exactly! <!-- s:) --> <!-- s:) -->
IL'ing is a bit painfull <!-- s:) --> <!-- s:) -->
|
|
|
|
|
Community Member
|
|
My bad. I too am not as strong in the IL department as I'd like. For now I just use Reflector with the language set to IL.
|
|
|
|
|
Community Member
|
|
I should also note that I found an add-in for Reflector called ReflexIL.
http://sebastien.lebreton.free.fr/reflexil/
The interface contains a means to create IL from C# in Reflector, useful for quickly comparing the generated IL of some bit of C#, as well as modifying the IL directly with useful descriptions of each instruction, as well as instruction composition validation, to ensure you are not trying to issue an operand that is not valid for the instruction, etc.
ldarg.0 - Loads the argument at index 0 onto the evaluation stack.
I find it helpful with my IL needs so I thought I'd share.
-Chris
|
|
|
|
|
Community Member
|
|
Thank you! Really neat tool. <!-- s:) --> <!-- s:) -->
|
|
|
|