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
Full Name: Stefan 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
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 674
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael 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
Full Name: Stefan Jauch


Return to PostSharp Laos