[Mono-list] Named parameters for Attributes
Greg Whelan
greg@gregwhelan.com
Thu, 09 May 2002 16:48:15 -0700
I'm trying to utilize an attribute which has named parameters.
ie. the first line in this code frag:
[Bar(Foo=2)]
public class Zippy {
}
Where the attribute is defined like so:
using System;
[AttributeUsage(AttributeTargets.Class)]
public sealed class BarAttribute : System.Attribute
{
public BarAttribute() {}
public int foo;
public int Foo {
get { return foo; }
set { foo = value; }
}
}
When I attempt to compile Zippy.cs I get:
[gregw@dhcp csharp]$ mcs -r Bar.dll --target library Zippy.cs
** (process:11532): WARNING **: unhandled exception
System.NullReferenceException: "A null value was found where an object
instance was required"
in Mono.CSharp.Attribute:Resolve ()
in Mono.CSharp.Attribute:ApplyAttributes ()
in Mono.CSharp.TypeContainer:Emit ()
in Mono.CSharp.RootContext:EmitCode ()
in Mono.CSharp.Driver:MainDriver ()
in Mono.CSharp.Driver:Main ()
As a wild-a**-guess to the source of the problem I notice that in the
attribute_arguments rule in cs-parser.jay that a null value is
mysteriously added to the args list
| named_argument_list
{
ArrayList args = new ArrayList ();
args.Add (null); // <----- huh?
args.Add ($1);
$$ = args;
}
Developing on Linux on an otherwise "working as expected" (aka
kicking-a** as expected) mono-0.11_baselabs-20020508.i386.rpm.
-Greg