473,569 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 GenericParamete r
value.

[AttributeUsage( AttributeTarget s.GenericParame ter)]
public class GenericAttribut e : 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: GenericAttribut e()]
public class Test<GenericTyp e>
{
}

but that produces the complier error "
Attribute 'BenericAttribu te' 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 5975
"Brian" <br********@hot mail.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 GenericParamete r
value.

[AttributeUsage( AttributeTarget s.GenericParame ter)]
public class GenericAttribut e : 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: GenericAttribut e()]
public class Test<GenericTyp e>
{
}

but that produces the complier error "
Attribute 'BenericAttribu te' 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********@hot mail.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 GenericParamete r
value.

[AttributeUsage( AttributeTarget s.GenericParame ter)]
public class GenericAttribut e : 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: GenericAttribut e()]
public class Test<GenericTyp e>
{
}

but that produces the complier error "
Attribute 'BenericAttribu te' 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*******@disc ussions.microso ft.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
2448
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 still no can do... Any info would be great!
0
926
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
2526
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 vs C++ templates. Does anyone knows a workaround to do this ? Thx : public class C<T> { private T myValue;
12
2726
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 it defines the language more completely. Great to use.
2
19230
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 System; using System.Collections.Generic;
9
5963
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 Experience Only, Please. ...
1
2426
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 "ThrowInConstructor" and "ThrowInFoo". First one throws "MyOwnException" in constructor, second one in "Foo()" method. There is a "GenericCatch" generics class...
7
3244
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 System.Collections.Generic namespace. Literature I have read on this ties generics in with collections, hence articulate their examples as such. That's fine,...
13
3804
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 application that needs implementations in both Java and C#. I have the Java side done, and it works fantastic, and the C# side is nearly there. The...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7968
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.