Metadata (attribute) injection
3 posts • Page 1 of 1
Metadata (attribute) injection
Just thinking... one very useful feature (that I can't see at the moment) would be the ability to add attributes at compile time. In particular, I'm thinking of generated classes (such as LINQ-to-SQL, LINQ-to-Entities, SOAP, WCF, etc); you can add a partial class with additional methods / class-attributes, but you can't add attributes to existing members. And if you edit the generated code it will get lost next time you rebuild etc.
So (for example) if the user defined a DisplayNameAspect that returns (perhaps) a CustomAttributeBuilder, i.e.
[DisplayNameAspect(Target="Bar", DisplayName="Hello world")]
class Foo {
public String Bar {get;set;}
}
then this would be as though we had:
class Foo {
[DisplayName("Hello world")]
public string Bar {get;set;}
}
Again; the main driver here being partial classes where the member (Bar) is outside of our direct control; and obviously the caller would need to do something to provide the attribute in a convenient way (maybe CustomAttributeBuilder, maybe something else).
Thoughts? Is this already supported?
Marc
So (for example) if the user defined a DisplayNameAspect that returns (perhaps) a CustomAttributeBuilder, i.e.
[DisplayNameAspect(Target="Bar", DisplayName="Hello world")]
class Foo {
public String Bar {get;set;}
}
then this would be as though we had:
class Foo {
[DisplayName("Hello world")]
public string Bar {get;set;}
}
Again; the main driver here being partial classes where the member (Bar) is outside of our direct control; and obviously the caller would need to do something to provide the attribute in a convenient way (maybe CustomAttributeBuilder, maybe something else).
Thoughts? Is this already supported?
Marc
- mgravell
- Posts: 2
- Joined: Wed Jul 02, 2008 3:57 pm
- First Name: Marc
- Last Name: Gravell
Re: Metadata (attribute) injection
Good idea.
It is not supported, but would be pretty easy to realize (combined with CompoundAspect).
It is not supported, but would be pretty easy to realize (combined with CompoundAspect).
Gael Fraiteur, project leader
- gfraiteur
- Site Admin
- Posts: 835
- Joined: Tue Dec 18, 2007 3:09 pm
- First Name: Gael
- Last Name: Fraiteur
- Company: postsharp.org
Re: Metadata (attribute) injection
Re the "something else", perhaps an easier option would be to clone the attributes from a prototype member (that might perhaps get removed in the process). Now to read up on compound aspect!
- mgravell
- Posts: 2
- Joined: Wed Jul 02, 2008 3:57 pm
- First Name: Marc
- Last Name: Gravell
3 posts • Page 1 of 1
