SharpCrafters Forum – Runtime Class Initialization

SharpCrafters Support Forum

        


Runtime Class Initialization Expand / Collapse
Author
Message
Posted 2/18/2010 5:03:14 PM


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
Post #699
Posted 2/18/2010 7:02:40 PM


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();
 }

}
Post #700
Posted 2/18/2010 8:04:12 PM


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();
 }

}
Post #701
Posted 2/18/2010 8:16:54 PM


Gael Fraiteur

SharpCrafters
Library PostSharp.dll, type PostSharp.Aspects.InstanceLevelAspect.

-g
Post #702
Posted 2/18/2010 8:44:55 PM


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
Post #703
« Prev Topic | Next Topic »


All times are GMT +1:00, Time now is 11:36am

Powered By InstantForum.NET v4.1.4 © 2010
Execution: 0.123. 9 queries. Compression Disabled.