How to transfer a resource item (string) to an aspect class?

Technical questions about PostSharp Laos.

How to transfer a resource item (string) to an aspect class?

Postby StefanJ on Wed Apr 16, 2008 2:07 pm

Hallo Gael,

I have to decide whether Laos will be the future solution for validating fields in our applications. So the following question seems to be critical for decision making:

How can I transfer a resource item (type string) to a class implementing an aspect? (The attached figure shows the scenario.)

Thanks a lot and best regards,
Stefan
You do not have the required permissions to view the files attached to this post.
StefanJ
 
Posts: 2
Joined: Tue Apr 15, 2008 3:47 pm
First Name: Stefan
Last Name: Jauch

Re: How to transfer a resource item (string) to an aspect class?

Postby gfraiteur on Wed Apr 16, 2008 2:15 pm

I guess you will use override the RuntimeInitialize method to ResourceManager you want:

Code: Select all

class TheAspect : OnFieldAccessAspect
{

  [NonSerialized] ResourceManager resourceManage;

  public override void RunTimeInitialize(FieldInfo field)
  {
    this.resourceManager = new ResourceManager( field.DeclaringType.FullName,
            field.DeclaringType.Assembly );
  }

}


Note that you would better cache the ResourceManager so that all fields of the same assembly use the same instance!

Gael
Gael Fraiteur, project leader
gfraiteur
Site Admin
 
Posts: 839
Joined: Tue Dec 18, 2007 3:09 pm
First Name: Gael
Last Name: Fraiteur
Company: postsharp.org

Re: How to transfer a resource item (string) to an aspect class?

Postby StefanJ on Wed Apr 16, 2008 8:42 pm

Hallo Gael,

It works very well - thanks a lot! :P

Best regards,
Stefan
StefanJ
 
Posts: 2
Joined: Tue Apr 15, 2008 3:47 pm
First Name: Stefan
Last Name: Jauch


Return to PostSharp Laos


cron