Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7811109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:02:39+00:00 2026-06-02T04:02:39+00:00

I was reading through a .NET 2.0 book and came across this sample code

  • 0

I was reading through a .NET 2.0 book and came across this sample code which gets the applications assembly description :

static void Main(string[] args)
{
    Assembly assembly = Assembly.GetExecutingAssembly();
    object[] attributes = 
        assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
    if (attributes.Length > 0)
    {
        AssemblyDescriptionAttribute descriptionAttribute =
            (AssemblyDescriptionAttribute)attributes[0];
        Console.WriteLine(descriptionAttribute.Description);
    }
    Console.ReadKey();
}

It’s quite a lot of code to simply get the assembly description and I would like to know if there’s a simpler way of doing this in .NET 3.5+ using LINQ or lambda expressions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:02:40+00:00Added an answer on June 2, 2026 at 4:02 am

    There isn’t, really. You can make it a bit ‘more fluent’ like this:

     var descriptionAttribute = assembly
             .GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)
             .OfType<AssemblyDescriptionAttribute>()
             .FirstOrDefault();
    
     if (descriptionAttribute != null) 
         Console.WriteLine(descriptionAttribute.Description);
    

    [EDIT changed Assembly to ICustomAttributeProvider, cf. answer by Simon Svensson)

    And if you need this kind of code a lot, make an extension method on ICustomAttributeProvider:

     public static T GetAttribute<T>(this ICustomAttributeProvider assembly, bool inherit = false) 
     where T : Attribute 
     {
         return assembly
             .GetCustomAttributes(typeof(T), inherit)
             .OfType<T>()
             .FirstOrDefault();
    }
    

    Since .Net 4.5, as Yuriy explained, an extension method is available in the framework:

    var descriptionAttribute = 
        assembly.GetCustomAttribute<AssemblyDescriptionAttribute>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading through the source code for ASP.NET MVC3, and I came across the
I was just reading through the MethodInfo type and came across this type and
I'm reading through the Professional iPhone Programming with MonoTouch and .NET/C# book, but I'm
I'm reading through the excellent online book http://nodebeginner.org/ and trying out the simple code
I've been reading through a few asp.net articles, and attempting some code, but I
I was reading through this post here MisfitGeek: Adding ASP.NET Membership to your OWN
I'm working my way through some ASP.NET MVC reading and I have a web
Reading through this question on multi-threaded javascript, I was wondering if there would be
I was reading through my javascript file, and two questions came to my mind:
I'm reading through head first design patterns at the moment and while the book

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.