--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
const deprecated = const _Deprecated();
class _Deprecated {
const _Deprecated();
}
class MyMetadata {
const MyMetadata();
}
@MyMetadata
var myVar1;
@MyMetadata
var myVar2;
const MY_METADATA = const MyMetadata();
class MyClass {
@inject
@Named('my-special-implementation')
SomeClass _someClass;
}
--
I filed a bug on this, to allow @Foo as shorthand for @Foo(), which removes the need for @foo:
@foo(SomeType)
for (var metadataMirror in mirror.metadata) {var meta = metadataMirror.reflectee;// Check for @MyAnnotation or @MyAnnotation(some,args)if (meta == MyAnnotation || meta is MyAnnotation) {... do stuff ...}}
On Thu, Oct 3, 2013 at 2:27 PM, Sean Eagan <seane...@gmail.com> wrote:
On Wed, Sep 25, 2013 at 12:02 PM, Sean Eagan <seane...@gmail.com> wrote:
I filed a bug on this, to allow @Foo as shorthand for @Foo(), which removes the need for @foo:So, there is a competing bug to allow runtimeType literals as annotation values:For example, in...@MyAnnotationvar foo;
... the metadata value will be interpreted as the class itself `MyAnnotation` instead of an instance of the class `const MyAnnotation()`.I can't think of any use cases for this, or similar functionality in other languages, and it seems quite error prone for people coming from Java/C#/etc where it's interpreted as an instance. I posted a question in the bug, but maybe someone here has an idea?The thing to the right of @ is just a constant expression
, the only magic is it saves you from writing the "const" keyword (since you already have the "@" there).
A type-literal should be valid expression there.
Anyway, if bug 11857 was fixed, it would be easy to have code that checks for both:for (var metadataMirror in mirror.metadata) {var meta = metadataMirror.reflectee;// Check for @MyAnnotation or @MyAnnotation(some,args)if (meta == MyAnnotation || meta is MyAnnotation) {
From using metadata more in Polymer.dart, I'm kinda leaning towards uppercase names, to avoid conflicting with the (crowded) camelCase namespace.