473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Attributes and Generics in C#

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
Nov 15 '05 #1
4 5964
"Brian" <br********@hotmail.com> schreef in bericht
news:05****************************@phx.gbl...
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
Nov 15 '05 #2
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
"Brian" <br********@hotmail.com> wrote in message
news:05****************************@phx.gbl...
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

Nov 15 '05 #3
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.
Nov 15 '05 #4
This NG is for the released product bits, Whidbey questions should be posted
to the whidbey NG's
http://communities.microsoft.com/new...idbey&slcid=us

Willy.

<an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
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.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
by: Bernardo Heynemann | last post by:
How can I use Generics? How can I use C# 2.0? I already have VS.NET 2003 Enterprise Edition and still can´t use generics... I´m trying to make a generic collection myCollection<vartype> and...
0
by: Wernfried Schwenkner | last post by:
I'm playing a little bit with 2.0 and generics. I have two classes public class UserCollection : Collection<User> { } public class User {
23
by: Luc Vaillant | last post by:
I need to initialise a typed parameter depending of its type in a generic class. I have tried to use the C++ template form as follow, but it doesn't work. It seems to be a limitation of generics...
12
by: Michael S | last post by:
Why do people spend so much time writing complex generic types? for fun? to learn? for use? I think of generics like I do about operator overloading. Great to have as a language-feature, as...
2
by: Ricebot | last post by:
Hi, I'm playing around with extended List<T> such that I have a generic list collection that is cloneable (fully, not shallow) and serializable. So far the impl looks like this. using...
9
by: sloan | last post by:
I'm not the sharpest knife in the drawer, but not a dummy either. I'm looking for a good book which goes over Generics in great detail. and to have as a reference book on my shelf. Personal...
1
by: Vladimir Shiryaev | last post by:
Hello! Exception handling in generics seems to be a bit inconsistent to me. Imagine, I have "MyOwnException" class derived from "ApplicationException". I also have two classes...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.