locked
WinRT C++ Attributes - Can we make our own?

    Question

  • There's a lot of usages of attributes in the WinRT API.  Can we make our own custom attributes?  If so what can we do with them?  Possibly a quick sample :)

     

    -Jer

    Tuesday, September 27, 2011 8:10 PM

Answers

All replies

  • Could you provide a specific example of an attribute implementation you are referring to?

     

    Thanks,

    -David

    Wednesday, September 28, 2011 9:41 PM
    Moderator
  • Theres MTAThread/STAThread attributes used on your "main" method.  There is also Windows::Foundation::Metadata::AttributeUsageAttribute.  All inherit from the Platform::Attribute.  I was curious if it is possible to make our own...and if we can, what can we do with them?

    I'm just trying to find out what all is possible with WinRT C++ in these early pre-release days.

    Thanks!

    -Jer

    Wednesday, September 28, 2011 11:02 PM
  • Jeremiah, yes this is possible. The XAML ContentPropertyAttribute is an example of a custom attribute.
    Ashish Shetty, Program Manager, Microsoft | http://nerddawg.blogspot.com
    Thursday, September 29, 2011 3:09 AM
  • Ignore my response above. I was wrong. The ContentPropertyAttribute is an example of a built-in attribute in Windows XAML.
    Ashish Shetty, Program Manager, Microsoft | http://nerddawg.blogspot.com
    Thursday, September 29, 2011 4:27 PM
  • While it may be technically possible to create custom attributes using C++, there is no mechanism to consume such custom attributes.  There is no supported mechanism for user created custom attributes in metadata.

     

    Larry

    Thursday, September 29, 2011 4:37 PM
  • Thanks for your response!  I was just curious if we could create attributes in a similar way to how they are used in C#.  Thanks for clearing this up!

     

    -Jer

    Thursday, September 29, 2011 6:55 PM