473,387 Members | 1,678 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,387 software developers and data experts.

Assembly: custom attributes

Hello,
my program loads a couple of DLLs. I use System.Reflection to obtain
information about them.

I a DLL, I have:
[assembly:AssemblyTitle("First plugin")]
[assembly:AssemblyCompany("MySelf")]
[assembly:AssemblyProduct("My first plugin")]

I tried to retrive these information in my program. RIght now, I can get
the types:
Object[] myAttributes = asm.GetCustomAttributes(false); //asm est un
Assembly
for(int i = 0; i < myAttributes.Length; i++)
{
Console.WriteLine("attribute {0}", myAttributes[i]);
}

=>
attribute System.Reflection.AssemblyProductAttribute
attribute System.Reflection.AssemblyCompanyAttribute
attribute System.Reflection.AssemblyTitleAttribute

But then I'm not able to get the values ("MySelf", "First plugin", ...).

Thank you

Julien
Nov 16 '05 #1
5 2198
But then I'm not able to get the values ("MySelf", "First plugin", ...).


Here's how to get "MySelf". The same principle can be used for the
other attributes.

AssemblyCompanyAttribute aca = myAttributes[i] as
AssemblyCompanyAttribute;
if ( aca != null )
Console.WriteLine( aca.Company );

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
Mattias Sjögren wrote:
But then I'm not able to get the values ("MySelf", "First plugin", ...).

Here's how to get "MySelf". The same principle can be used for the
other attributes.

AssemblyCompanyAttribute aca = myAttributes[i] as
AssemblyCompanyAttribute;
if ( aca != null )
Console.WriteLine( aca.Company );

Mattias


Thank you. But this means I know all the potential attributes name
before I load the DLL. How can I do if I don't know the different types?
Julien
Nov 16 '05 #3
How can I do if I don't know the different types?


Use Reflection on the attribute objects.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
Mattias Sjögren wrote:
How can I do if I don't know the different types?

Use Reflection on the attribute objects.

Mattias


Actually, I thought I could create any CustomAttribute I want, but it
looks like the list of CustomAttribute is already define (i.e.
AssemblyMyVariable cannot be created).

Thanks
Julien
Nov 16 '05 #5
You can create and use attributes as you see fit:

[AttributeUsage(AttributeTargets.Assembly)]
public class MyCustomAttribute : Attribute {
....
}

in AssemblyInfo.cs:
[assembly: MyCustomAttribute()]

"julien" <ju****@sobrier.net> wrote in message
news:42*********************@news.free.fr...
Mattias Sjögren wrote:
How can I do if I don't know the different types?

Use Reflection on the attribute objects.

Mattias


Actually, I thought I could create any CustomAttribute I want, but it
looks like the list of CustomAttribute is already define (i.e.
AssemblyMyVariable cannot be created).

Thanks
Julien

Nov 16 '05 #6

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

Similar topics

1
by: AlexB | last post by:
A windows forms .NET application has various built in attributes like: <Assembly: AssemblyTitle("MyAssembly")> <Assembly: AssemblyDescription("Blahblah")> <Assembly: AssemblyCompany("XYZ")> ...
2
by: pothik05 | last post by:
Hi: I have created a custom Attribute for the assembly and lets call it AssemblyAbc. I want it to be displayed with the other Assembly Information. If you right click the dll, click Properties...
3
by: Madhav Desetty | last post by:
I have a legacy C/C++ header file which I use to set the version for DLLs thru' the .rc files while compiling legacy DLLs every day. I update this header file for every build and would like to use...
5
by: Sky | last post by:
Hello: I understand that I can query an class def to find if it has a specific custom attribute -- but if i wanted to find all classes in an assembly that have that attribute, is there a way? ...
1
by: Luis Esteban Valencia | last post by:
Hello. I got an error on my program. the code is very simple private void btnsubmit_Click(object sender, System.EventArgs e) { string requestLocation =...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
0
by: murl | last post by:
I'm making a project to read custom attributes from assemblies, and in order to read them using the assembly.getCustomAttributes(type, false) method, I have to add my custom attribute library to...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
3
by: cristalink | last post by:
Hi, I have a C++/CLI DLL which I marked with in a cpp file. Is there a standard tool from Microsoft that takes a .DLL file and displays all the .NET attributes of the assembly? Thanks, ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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...
0
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,...
0
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...

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.