|
|
|
Community Member
|
|
Hi, I have a question, how can I use PostSharp library to execute a specified method each time a specified class is instantiated at runtime? for example: public class Test { void Initialize() {} } I would like to call Initialize method, after class instantiation.. Regards Rabeeh Abla
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
Using PostSharp 2.0, you could try something like this:
class MyAspect : InstanceLevelAspect {
[ImportMember("Initialize")] public Action InitializeMethod;
public override void RuntimeInitializeInstance() { this.InitializeMethod(); }
}
|
|
|
|
|
Community Member
|
|
Thank you for your reply, I downloaded the latest PostSharp library X64 version, but I did not find the Type "InstanceLevelAspect".
Regards Rabeeh
Using PostSharp 2.0, you could try something like this: class MyAspect : InstanceLevelAspect {
[ImportMember("Initialize")] public Action InitializeMethod;
public override void RuntimeInitializeInstance() { this.InitializeMethod(); }
}
|
|
|
|
|
Gael Fraiteur
SharpCrafters
|
|
Library PostSharp.dll, type PostSharp.Aspects.InstanceLevelAspect.
-g
|
|
|
|
|
Community Member
|
|
Thank you, it worked well, I had PostSharp 1.5 installed first, then I installed the latest PostSharp 2.0..
Regards
Library PostSharp.dll, type PostSharp.Aspects.InstanceLevelAspect.
-g
|
|
|
|