Creating Properties

Do you program directly PostSharp.CodeModel or another low-level API and need help? Put your questions here and we will try to answer.

Creating Properties

Postby Haukinger on Thu May 08, 2008 12:14 pm

Hi all !

Is it possible to use PostSharp as kind of Preprocessor that creates new Properties ?
E.g. I've got something like this:

Code: Select all
class AClass
{
  private int myValue;
  [TheAttribute]
  public int MyProperty
  {
    get { return myvalue; }
  }
}


I want PostSharp (using TheAttribute) to expand it to:
Code: Select all
class AClass
{
  private int myValue;
  public static PropertyInfo _MyProperty { get { return typeof(AClass).GetProperty("MyProperty"); } }
  public int MyProperty
  {
    get { return myvalue; }
  }
}


Can PostSharp do this ?

Hauke
Haukinger
 
Posts: 2
Joined: Thu May 08, 2008 11:52 am
Full Name: Hauke Lasinger

Re: Creating Properties

Postby gfraiteur on Thu May 08, 2008 1:24 pm

You can use PostSharp as a post-processor. The new property will not be visible from C# code of the same assembly. However, it will be visible to C# code of other assemblies.

However, to cannot add new properties using PostSharp Laos. You need to develop your own aspect using PostSharp Core.

.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: Creating Properties

Postby Haukinger on Thu May 08, 2008 1:54 pm

Ok, that should be enough. Can you give me a hint where to start with developing my aspect ?
Haukinger
 
Posts: 2
Joined: Thu May 08, 2008 11:52 am
Full Name: Hauke Lasinger

Re: Creating Properties

Postby gfraiteur on Thu May 08, 2008 2:15 pm

This series of articles should help:

http://www.sitechno.com/Blog/Introducin ... onV01.aspx

Good luck.

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


Return to PostSharp Core