Introduction
We have very good features in .Net based on the application version and customizations. Basically .Net provide unique assembly file for the common setting within the projects. And we can play with that file within code as well.
How I can say that?
The .Net provides few attributes based on the assembly manipulations. Suppose we want to know the current version of the product, then we want to access the assembly file and get an answer from that file. To achieve the product version attribute in the assembly file, we must use the AssemblyVersionAttribute attribute. And lots of customization attributes exist in the .Net class library based on the assembly file.
List of commonly used attributes.
- AssemblyTitleAttribute
- AssemblyCompanyAttribute
- AssemblyVersionAttribute
- AssemblyProductAttribute
- AssemblyCopyrightAttribute
- AssemblyDescriptionAttribute
This article provides a simple class with commonly using attributes and gets information from the assembly about the product.
Let's see the class.
Let us see how to get a product description from the assembly file
- public static string ProductDescription
- {
- get
- {
-
- Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
- if (assembly != null)
- {
-
- object[] customAttributes = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
- if ((customAttributes != null) && (customAttributes.Length > 0))
- {
- productDescription = ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
- }
- if (string.IsNullOrEmpty(productDescription))
- {
- productDescription = string.Empty;
- }
- }
- return productDescription;
- }
- }
We want to get all custom attribute from the assembly file based on the AssemblyDescriptionAttribute.
- object[] customAttributes = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
After this, access the first attribute in the collections, and get the value from that
- productDescription = ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
Conclusion
The .Net provides good customization based on the assembly file. So please try to access all other attributes in the assembly file and enjoy.