473,662 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve Classes with Attribute

Besides looping through all the types in an assembly, is there any way to
retreive all of the classes that have a custome attribute applied?

For example, I have a PersistentAttri bute, I won't to retrieve all of the
types that have the attribute applied. The type can only be used at the
class level. I would like ot avoid looping through all the types of the
assembly if I don't have to.
Aug 17 '05 #1
2 1416
Jesse <Je***@discussi ons.microsoft.c om> wrote:
Besides looping through all the types in an assembly, is there any way to
retreive all of the classes that have a custome attribute applied?
Not that I know of.
For example, I have a PersistentAttri bute, I won't to retrieve all of the
types that have the attribute applied. The type can only be used at the
class level. I would like ot avoid looping through all the types of the
assembly if I don't have to.


Why, out of interest? Have you got concrete data showing that this
would be a problem in terms of performance?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 17 '05 #2
>Besides looping through all the types in an assembly, is there any way to
retreive all of the classes that have a custome attribute applied?

For example, I have a PersistentAttri bute, I won't to retrieve all of the
types that have the attribute applied. The type can only be used at the
class level. I would like ot avoid looping through all the types of the
assembly if I don't have to.

Well you could use an assembly or module level attribute instead, that
simply lists the names of all classes you're interested in. That way
you can avoid loading metadata for all types.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Aug 18 '05 #3

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

Similar topics

5
1928
by: Tim Henderson | last post by:
Hello I want to creat a program that can inspect a set of classes that i have made and spit out a savable version of these classes. To do this I need to be able to inspect each class and get all of its instance data as well as information about a particular meathod. This is what i want it to do: class song:
4
1507
by: Paul | last post by:
Hi! I have a problem: I've declared some classes and decorated them with my Custom Attributes. (say ClassA and ClassB) Now I have some Type member (in fact this is FieldInfo.FieldType) which is eq. typeof (ClassB). And when I call GetCustomAttributes() for this Type I never gets the attribute, that should be there. When I call GetType().GetCustonAttributes() everything works fine. Doeas object of the requested type for attributes must...
10
2429
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and load as a 3rd partial class. This would be handy so i can generate standard code into one of the partial classes, while having my custom code untouched
3
7540
by: Oenone | last post by:
I am currently in the process of upgrading my VB.NET applications and DLLs from VS2003 to VS2005. Everything seems to be going fine, but I've had a couple of warnings that I don't understand. In one of my DLLs I define a MustInherit base class with various properties and methods. In another DLL I inherit from that class to create a custom derived class. I am getting the following warning in the IDE: 'DerivedClass' is not CLS-compliant...
2
315
by: Jesse | last post by:
Besides looping through all the types in an assembly, is there any way to retreive all of the classes that have a custome attribute applied? For example, I have a PersistentAttribute, I won't to retrieve all of the types that have the attribute applied. The type can only be used at the class level. I would like ot avoid looping through all the types of the assembly if I don't have to.
18
1615
by: Donn Ingle | last post by:
Hi, I'm getting myself really confused. I have three classes. Two of them need to reference the third, like so: Canvas ---Stack <--- Thing I am doing this right now: s = Stack()
5
9441
by: =?Utf-8?B?QXhlbCBEYWhtZW4=?= | last post by:
Hi, I've created a class library assembly containing several string resource files, like: - TableColumns.resx - TableColumns.de.resx - General.resx - General.de.resx
7
2677
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
5
1470
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other words, I can do this: .... pass .... 33
0
8432
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6185
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.