Attributes and Generics in C#

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi,

According to An Introduction to C# Generics
(http://www.msdn.microsoft.com/vcsharp/default.aspx?
pull=/library/en-us/dv_vstechart/html/csharp_generics.asp)
the AttributeUsage enumeration has a GenericParameter
value.

[AttributeUsage(AttributeTargets.GenericParameter)]
public class GenericAttribute : Attribute
{
}

My question is how do you apply this to a generic type
parameter or the generic class? I've tried using
the "type:" attribute location by applying it to the class
like:

[type: GenericAttribute()]
public class Test<GenericType>
{
}

but that produces the complier error "
Attribute 'BenericAttribute' is not valid on this
declaration type. It is valid on '' declarations only.

But the single quoutes doesn't contain a attribute
location, so is this not implemented yet?

Thanks,
Brian
 
Brian said:
Hi,

According to An Introduction to C# Generics
(http://www.msdn.microsoft.com/vcsharp/default.aspx?
pull=/library/en-us/dv_vstechart/html/csharp_generics.asp)
the AttributeUsage enumeration has a GenericParameter
value.

[AttributeUsage(AttributeTargets.GenericParameter)]
public class GenericAttribute : Attribute
{
}

My question is how do you apply this to a generic type
parameter or the generic class? I've tried using
the "type:" attribute location by applying it to the class
like:

[type: GenericAttribute()]
public class Test<GenericType>
{
}

but that produces the complier error "
Attribute 'BenericAttribute' is not valid on this
declaration type. It is valid on '' declarations only.

But the single quoutes doesn't contain a attribute
location, so is this not implemented yet?

Thanks,
Brian

If you read the article again you will see in the introduction it states
"Generics are the most powerful and anticipated feature of C# 2.0". So it's
not yet implemented in the current version.

Yves
 
Hello,

If you use the .NET 1.1 compiler, Generics wont work. This is implemented in
the 2.0 compiler, that is not publicy available yet (if you have an MSDN
subscription, you can get Visual Studio .NET Whidbey, which should be able
to compile the code).

--
Regards,
Kristofer Gafvert - IIS MVP
Reply to newsgroup only. Remove NEWS if you must reply by email, but please
do not.
www.ilopia.com - FAQ and Tutorials for Windows Server 2003
 
Sorry, I should of mentioned that I am using VS.Net
Whidbey and the .Net Framework 2.0.

Right now I am guessing that this paticular feature is not
yet implemented, because the error message doesn't provide
an alternative attribute location, but then I could be
wrong.
 
Back
Top